{"id":906,"date":"2016-04-20T15:36:07","date_gmt":"2016-04-20T15:36:07","guid":{"rendered":"https:\/\/ionic.io\/blog\/?p=906"},"modified":"2023-07-18T11:48:18","modified_gmt":"2023-07-18T15:48:18","slug":"10-minutes-with-ionic-2-calling-an-api","status":"publish","type":"post","link":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api","title":{"rendered":"10 Minutes with Ionic 2: Calling an API"},"content":{"rendered":"<blockquote><p>2020 Update: Building Ionic 1, 2, or 3 apps? We recommend Ionic 4 and above &#8211; learn <a href=\"https:\/\/ionicframework.com\/docs\/reference\/migration\">how to migrate<\/a>. For an updated way to make API calls natively, see the <a href=\"https:\/\/github.com\/capacitor-community\/http\">Capacitor Community HTTP plugin<\/a>.<\/p><\/blockquote>\n<p>Getting up and running with Ionic 2 using the Ionic CLI is super simple for anyone with web development experience. In our first two articles <a href=\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-hello-world\/\">10 Minutes with Ionic 2: Hello World<\/a> and <a href=\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-adding-pages-and-navigation\/\">10 Minutes with Ionic 2: Adding Pages and Navigation<\/a>, we looked at the basics of creating an Ionic app. In this article, we&#8217;ll build on what we learned and look at calling backend APIs using a class.<br \/>\n<!--more--><\/p>\n<h3>Ionic Start<\/h3>\n<p>We&#8217;ll start by creating an app with the blank template, using <code>ionic start<\/code>.<\/p>\n<pre><code>ionic start apiApp blank --v2 --ts\n<\/code><\/pre>\n<p>As described in the first post of this series, we now have some basic plumbing, including a <code>home<\/code> page.<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\" alt=\"Default File Structure\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" class=\"lazyload\" style=\"--smush-placeholder-width: 196px; --smush-placeholder-aspect-ratio: 196\/134;\" \/><noscript><img decoding=\"async\" src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\" alt=\"Default File Structure\" \/><\/noscript><\/p>\n<h3>Creating a New Provider<\/h3>\n<p>Let&#8217;s look at adding a new provider (also known as a service), which will be used to make an HTTP request to an API. Similar to the last post, where we created a page, the CLI makes this significantly easier by providing automatic provider generation, using <code>ionic g<\/code>. After changing into the project directory (<code>cd apiApp<\/code>), let&#8217;s create a new provider called <code>PeopleService<\/code>, using the CLI.<\/p>\n<pre><code>ionic g provider PeopleService\n<\/code><\/pre>\n<p>The CLI will generate the an <code>@Injectable<\/code> class called <code>PeopleService<\/code> in <code>app\/providers\/people-service\/people-service.ts<\/code>.<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/04\/people-service-directory-ts.png\" alt=\"New project structure with about page\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" class=\"lazyload\" style=\"--smush-placeholder-width: 200px; --smush-placeholder-aspect-ratio: 200\/155;\" \/><noscript><img decoding=\"async\" src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/04\/people-service-directory-ts.png\" alt=\"New project structure with about page\" \/><\/noscript><\/p>\n<p>This class will have the basic boilerplate code inside of a <code>load<\/code> method to make an HTTP request.<\/p>\n<pre><code>load() {\n  if (this.data) {\n    \/\/ already loaded data\n    return Promise.resolve(this.data);\n  }\n\n  \/\/ don&#039;t have the data yet\n  return new Promise(resolve =&gt; {\n    \/\/ We&#039;re using Angular HTTP provider to request the data,\n    \/\/ then on the response, it&#039;ll map the JSON data to a parsed JS object.\n    \/\/ Next, we process the data and resolve the promise with the new data.\n    this.http.get(&#039;path\/to\/data.json&#039;)\n      .map(res =&gt; res.json())\n      .subscribe(data =&gt; {\n        \/\/ we&#039;ve got back the raw data, now generate the core schedule data\n        \/\/ and save the data for later reference\n        this.data = data;\n        resolve(this.data);\n      });\n  });\n}\n<\/code><\/pre>\n<h3>Random User API<\/h3>\n<p>The <a href=\"https:\/\/randomuser.me\/\" target=\"_blank\" rel=\"noopener\">Random User Generator<\/a> is a free API that generates data of fake users, including names, emails, pictures, etc. It is a very helpful API for doing mockups and learning. Making an HTTP request to <code>https:\/\/randomuser.me\/api\/<\/code> will return a JSON response similar to the following:<\/p>\n<pre><code>{\n  &quot;results&quot;:[\n    {\n      &quot;gender&quot;:&quot;male&quot;,\n      &quot;name&quot;:{\n        &quot;title&quot;:&quot;mr&quot;,\n        &quot;first&quot;:&quot;eugene&quot;,\n        &quot;last&quot;:&quot;jordan&quot;\n      },\n      &quot;location&quot;:{\n        &quot;street&quot;:&quot;3277 green rd&quot;,\n        &quot;city&quot;:&quot;australian capital territory&quot;,\n        &quot;state&quot;:&quot;queensland&quot;,\n        &quot;postcode&quot;:275\n      },\n      &quot;email&quot;:&quot;eugene.jordan@example.com&quot;,\n      &quot;login&quot;:{\n        &quot;username&quot;:&quot;beautifulbutterfly703&quot;,\n        &quot;password&quot;:&quot;redhot&quot;,\n        &quot;salt&quot;:&quot;tva1i6Oo&quot;,\n        &quot;md5&quot;:&quot;a4231f30aa1fcfe46e4c7c4537a4bf11&quot;,\n        &quot;sha1&quot;:&quot;d6051a921eba285bbeccd95388332f92a50047ce&quot;,\n        &quot;sha256&quot;:&quot;093b0e1b429a105902f91e4be28c9dc12629701924312d63d55cdfd556d54c38&quot;\n      },\n      &quot;registered&quot;:1000882268,\n      &quot;dob&quot;:537587321,\n      &quot;phone&quot;:&quot;02-4894-6208&quot;,\n      &quot;cell&quot;:&quot;0477-498-405&quot;,\n      &quot;id&quot;:{\n        &quot;name&quot;:&quot;TFN&quot;,\n        &quot;value&quot;:&quot;571061435&quot;\n      },\n      &quot;picture&quot;:{\n        &quot;large&quot;:&quot;https:\/\/randomuser.me\/api\/portraits\/men\/12.jpg&quot;,\n        &quot;medium&quot;:&quot;https:\/\/randomuser.me\/api\/portraits\/med\/men\/12.jpg&quot;,\n        &quot;thumbnail&quot;:&quot;https:\/\/randomuser.me\/api\/portraits\/thumb\/men\/12.jpg&quot;\n      },\n      &quot;nat&quot;:&quot;AU&quot;\n    }\n  ],\n  &quot;info&quot;:{\n    &quot;seed&quot;:&quot;8eb0b2c2e327a185&quot;,\n    &quot;results&quot;:1,\n    &quot;page&quot;:1,\n    &quot;version&quot;:&quot;1.0&quot;\n  }\n}\n<\/code><\/pre>\n<p>If we modify our request to <code>https:\/\/randomuser.me\/api\/?results=10<\/code>, the <code>results<\/code> array in the response will contain ten users. Let&#8217;s put this in our <code>PeopleService<\/code>. We will need to make a couple of changes to the code the provider gave us. First, let&#8217;s put in the URL:<\/p>\n<pre><code>this.http.get(&#039;https:\/\/randomuser.me\/api\/?results=10&#039;)\n<\/code><\/pre>\n<p>Currently, our code stores\/returns the whole response. However, we only want to return the <code>results<\/code> array in the response. We&#8217;ll modify the <code>.subscribe<\/code> method:<\/p>\n<pre><code>.subscribe(data =&gt; {\n  this.data = data.results;\n  resolve(this.data);\n});\n<\/code><\/pre>\n<p>Now, our method, when called, will return a promise, which will resolve with an array of users when we get a response back from the API.<\/p>\n<h3>Calling PeopleService<\/h3>\n<p>Let&#8217;s take a look at calling our PeopleService and outputting the results as a list on our home page. First, inside <code>app\/pages\/home\/home.ts<\/code>, we need to import our service:<\/p>\n<pre><code>import {PeopleService} from &#039;..\/..\/providers\/people-service\/people-service&#039;;\n<\/code><\/pre>\n<p>Next, in our <code>@Page<\/code> decorator, we will need to add our service as a provider.<\/p>\n<pre><code>@Page({\n  templateUrl: &#039;build\/pages\/home\/home.html&#039;,\n  providers: [PeopleService]\n})\nexport class HomePage {\n<\/code><\/pre>\n<p>Now, we can add a constructor to our page, create a <code>people<\/code> property, import the PeopleService, and assign the <code>PeopleService<\/code> to a property of the class.<\/p>\n<pre><code>export class HomePage {\n  public people: any;\n\n  constructor(public peopleService: PeopleService){\n\n  }\n}\n<\/code><\/pre>\n<p>Let&#8217;s add a method to our <code>HomePage<\/code> class called <code>loadPeople<\/code> that will call our <code>peopleService.load<\/code> method and assign the result of the promise in a <code>people<\/code> property of the class.<\/p>\n<pre><code>loadPeople(){\n  this.peopleService.load()\n  .then(data =&gt; {\n    this.people = data;\n  });\n}\n<\/code><\/pre>\n<p>Finally, we will call this method from our constructor.<\/p>\n<pre><code>export class HomePage {\n  public people: any;\n\n  constructor(public peopleService: PeopleService){\n    this.loadPeople();\n  }\n\n  loadPeople(){\n    this.peopleService.load()\n    .then(data =&gt; {\n      this.people = data;\n    });\n  }\n}\n<\/code><\/pre>\n<p>Now that our class is getting the data, let&#8217;s modify our template for this page (<code>app\/pages\/home.html<\/code>) to list out users with their picture, first name, last name, and email. We&#8217;ll accomplish this by looping through our <code>people<\/code> array property using <code>ngFor<\/code>.<\/p>\n<pre><code>&lt;ion-navbar *navbar&gt;\n  &lt;ion-title&gt;\n    Home\n  &lt;\/ion-title&gt;\n&lt;\/ion-navbar&gt;\n\n&lt;ion-content class=&quot;home&quot;&gt;\n  &lt;ion-list&gt;\n    &lt;ion-item *ngFor=&quot;#person of people&quot;&gt;\n      &lt;ion-avatar item-left&gt;\n        &lt;img src=&quot;{{person.picture.thumbnail}}&quot;&gt;\n      &lt;\/ion-avatar&gt;\n      &lt;h2&gt;{{person.name.first}} {{person.name.last}}&lt;\/h2&gt;\n      &lt;p&gt;{{person.email}}&lt;\/p&gt;\n    &lt;\/ion-item&gt;\n  &lt;\/ion-list&gt;\n&lt;\/ion-content&gt;\n<\/code><\/pre>\n<h3>Serve<\/h3>\n<p>Finally, in the CLI, we&#8217;ll run <code>ionic serve<\/code> to view our app in the browser:<\/p>\n<pre><code>ionic serve\n<\/code><\/pre>\n<p>You should end up with something similar to the following in your browser:<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/output2.png\" alt=\"Screenshot of Browser Output\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" class=\"lazyload\" style=\"--smush-placeholder-width: 335px; --smush-placeholder-aspect-ratio: 335\/718;\" \/><noscript><img decoding=\"async\" src=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/output2.png\" alt=\"Screenshot of Browser Output\" \/><\/noscript><\/p>\n<h3>Conclusion<\/h3>\n<p>In under ten minutes, using the power of the Ionic CLI and some simple code, we have created an app that interacts with a backend API. This functionality is needed to create most apps, and this ability to get it working quickly will help you greatly on your journey toward creating the next #1 app in the app stores!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020 Update: Building Ionic 1, 2, or 3 apps? We recommend Ionic 4 and above &#8211; learn how to migrate. For an updated way to make API calls natively, see the Capacitor Community HTTP plugin. Getting up and running with Ionic 2 using the Ionic CLI is super simple for anyone with web development experience. [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"publish_to_discourse":"0","publish_post_category":"23","wpdc_auto_publish_overridden":"","wpdc_topic_tags":"","wpdc_pin_topic":"","wpdc_pin_until":"","discourse_post_id":"","discourse_permalink":"","wpdc_publishing_response":"","wpdc_publishing_error":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[124],"tags":[3,13,25],"class_list":["post-906","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-ionic","tag-ionic-2","tag-tutorials"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v23.0 (Yoast SEO v23.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Minutes with Ionic 2: Calling an API - Ionic Blog<\/title>\n<meta name=\"description\" content=\"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Minutes with Ionic 2: Calling an API\" \/>\n<meta property=\"og:description\" content=\"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\" \/>\n<meta property=\"og:site_name\" content=\"Ionic Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-04-20T15:36:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-18T15:48:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\" \/>\n<meta name=\"author\" content=\"Andrew McGivery\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@andrewmcgivery\" \/>\n<meta name=\"twitter:site\" content=\"@ionicframework\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew McGivery\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#article\",\"isPartOf\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\"},\"author\":{\"name\":\"Andrew McGivery\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/f919a9d571424a39c0ec8ce6d44755e7\"},\"headline\":\"10 Minutes with Ionic 2: Calling an API\",\"datePublished\":\"2016-04-20T15:36:07+00:00\",\"dateModified\":\"2023-07-18T15:48:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\"},\"wordCount\":599,\"commentCount\":92,\"publisher\":{\"@id\":\"https:\/\/ionic.io\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage\"},\"thumbnailUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\",\"keywords\":[\"Ionic\",\"Ionic 2\",\"Tutorials\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\",\"url\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\",\"name\":\"10 Minutes with Ionic 2: Calling an API - Ionic Blog\",\"isPartOf\":{\"@id\":\"https:\/\/ionic.io\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage\"},\"thumbnailUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\",\"datePublished\":\"2016-04-20T15:36:07+00:00\",\"dateModified\":\"2023-07-18T15:48:18+00:00\",\"description\":\"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.\",\"breadcrumb\":{\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage\",\"url\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\",\"contentUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png\",\"width\":196,\"height\":134},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ionic.io\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Minutes with Ionic 2: Calling an API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ionic.io\/blog\/#website\",\"url\":\"https:\/\/ionic.io\/blog\/\",\"name\":\"ionic.io\/blog\",\"description\":\"Build amazing native and progressive web apps with the web\",\"publisher\":{\"@id\":\"https:\/\/ionic.io\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ionic.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/ionic.io\/blog\/#organization\",\"name\":\"Ionic\",\"url\":\"https:\/\/ionic.io\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png\",\"contentUrl\":\"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png\",\"width\":1920,\"height\":854,\"caption\":\"Ionic\"},\"image\":{\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/ionicframework\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/f919a9d571424a39c0ec8ce6d44755e7\",\"name\":\"Andrew McGivery\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ionic.io\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/30cc07af4f34ecef53282a28baa6b213feb275e5abbd28b62d197851aff4ca7e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/30cc07af4f34ecef53282a28baa6b213feb275e5abbd28b62d197851aff4ca7e?s=96&d=mm&r=g\",\"caption\":\"Andrew McGivery\"},\"description\":\"My name is Andrew McGivery. I currently work full time as an application developer at Manulife Financial in Canada.\",\"sameAs\":[\"http:\/\/www.mcgivery.com\/\",\"https:\/\/x.com\/andrewmcgivery\"],\"url\":\"https:\/\/ionic.io\/blog\/author\/andrewmcgivery\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"10 Minutes with Ionic 2: Calling an API - Ionic Blog","description":"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api","og_locale":"en_US","og_type":"article","og_title":"10 Minutes with Ionic 2: Calling an API","og_description":"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.","og_url":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api","og_site_name":"Ionic Blog","article_published_time":"2016-04-20T15:36:07+00:00","article_modified_time":"2023-07-18T15:48:18+00:00","og_image":[{"url":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png"}],"author":"Andrew McGivery","twitter_card":"summary_large_image","twitter_creator":"@andrewmcgivery","twitter_site":"@ionicframework","twitter_misc":{"Written by":"Andrew McGivery","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#article","isPartOf":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api"},"author":{"name":"Andrew McGivery","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/f919a9d571424a39c0ec8ce6d44755e7"},"headline":"10 Minutes with Ionic 2: Calling an API","datePublished":"2016-04-20T15:36:07+00:00","dateModified":"2023-07-18T15:48:18+00:00","mainEntityOfPage":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api"},"wordCount":599,"commentCount":92,"publisher":{"@id":"https:\/\/ionic.io\/blog\/#organization"},"image":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage"},"thumbnailUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png","keywords":["Ionic","Ionic 2","Tutorials"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api","url":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api","name":"10 Minutes with Ionic 2: Calling an API - Ionic Blog","isPartOf":{"@id":"https:\/\/ionic.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage"},"image":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage"},"thumbnailUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png","datePublished":"2016-04-20T15:36:07+00:00","dateModified":"2023-07-18T15:48:18+00:00","description":"In this article, we\u2019ll build on what we learned in previous articles and look at calling backend APIs using a class.","breadcrumb":{"@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#primaryimage","url":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png","contentUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2016\/03\/files-ts.png","width":196,"height":134},{"@type":"BreadcrumbList","@id":"https:\/\/ionic.io\/blog\/10-minutes-with-ionic-2-calling-an-api#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ionic.io\/blog"},{"@type":"ListItem","position":2,"name":"10 Minutes with Ionic 2: Calling an API"}]},{"@type":"WebSite","@id":"https:\/\/ionic.io\/blog\/#website","url":"https:\/\/ionic.io\/blog\/","name":"ionic.io\/blog","description":"Build amazing native and progressive web apps with the web","publisher":{"@id":"https:\/\/ionic.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ionic.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ionic.io\/blog\/#organization","name":"Ionic","url":"https:\/\/ionic.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png","contentUrl":"https:\/\/ionic.io\/blog\/wp-content\/uploads\/2020\/10\/white-on-color.png","width":1920,"height":854,"caption":"Ionic"},"image":{"@id":"https:\/\/ionic.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/ionicframework"]},{"@type":"Person","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/f919a9d571424a39c0ec8ce6d44755e7","name":"Andrew McGivery","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ionic.io\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/30cc07af4f34ecef53282a28baa6b213feb275e5abbd28b62d197851aff4ca7e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/30cc07af4f34ecef53282a28baa6b213feb275e5abbd28b62d197851aff4ca7e?s=96&d=mm&r=g","caption":"Andrew McGivery"},"description":"My name is Andrew McGivery. I currently work full time as an application developer at Manulife Financial in Canada.","sameAs":["http:\/\/www.mcgivery.com\/","https:\/\/x.com\/andrewmcgivery"],"url":"https:\/\/ionic.io\/blog\/author\/andrewmcgivery"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts\/906","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/comments?post=906"}],"version-history":[{"count":1,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts\/906\/revisions"}],"predecessor-version":[{"id":5487,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/posts\/906\/revisions\/5487"}],"wp:attachment":[{"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/media?parent=906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/categories?post=906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ionic.io\/blog\/wp-json\/wp\/v2\/tags?post=906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}