Querying API sources using HTTP services in Angular
Hardcoding parameters into HTTP requests is a valid approach to making simple calls to an API resource, but often we compose requests based on the state of our application. One of the nice things about a large web application framework, such as Angular, is that it has tools such as URLSearchParams
that make querying APIs with configurable parameters very easy to wire into our application's logic.
Getting ready
Our blog is loading a paginated data-source for its content. This is efficient from an API performance point of view, but our users will not be able to read more than the first page of blog posts. We will need to pass along a pageToken
parameter to the Blogger API so that we can request the next page of blog posts. Let's add a More Posts
button to the bottom of our blog post list page that will request the next page of posts, as well as every sequential page after that the user wants to view.
How to do it...
Let's perform the following...