Retrieving API data using HTTP services in Angular
Single page applications such as Angular are often a component in service-oriented architecture (SOA) that relies on external web services as the data sources for our web application. Introducing networked services into our application also brings with it a lot of asynchronous behaviors that we have to resolve both technically, and in our user interface.
The most common form of interaction between these services and a frontend application is via an HTTP request to a RESTful API. In this section, we will cover how to connect to a RESTful API in Angular and work with that data in our application.
Getting ready
Let's wire our BlogPostsService
to an actual external API source. We could mock our blog API using Angular's InMemoryDataService
to create a more realistic prototype data source. However, considering that would only be a marginal improvement on the last section, let's instead use a publicly available blog post API for this section.
First...