Interacting with RESTful APIs
In this chapter, we will build a page that lists blog posts fetched from a REST API, as well as also a form to submit blog posts to the REST API. Through this, we will learn about various approaches to interacting with a REST API from a React component.
The first approach will be using React’s useEffect
hook with the browser’s fetch
function. As part of this process, we learn how to use a type assertion function to strongly type the data from a REST API. We will then use the data loading capability of React Router and experience its benefits. After that, we will move on to use a popular library called React Query and experience its benefits, before using React Query and React Router together to get the best of both these libraries.
So, in this chapter, we’ll cover the following topics:
- Getting set up
- Using the effect hook with fetch
- Posting data with fetch
- Using React Router
- Using React Query
- Using...