Defining the API layer for the features
The API layer will be defined in the api
folder of every feature. An API request can be either a query or a mutation. A query describes requests that only fetch data. A mutation describes an API call that mutates data on the server.
For every API request, we will have a file that includes and exports an API request definition function and a hook for consuming the request inside React. For the request definition functions, we will be using the API client we just created with Axios, and for the hooks, we will be using the hooks from React Query.
We’ll learn how to implement it in action in the following sections.
Jobs
For the jobs
feature, we have three API calls:
GET /jobs
GET /jobs/:jobId
POST /jobs
Get jobs
Let’s start with the API call that fetches jobs. To define it in our application, let’s create the src/features/jobs/api/get-jobs.ts
file and add the following:
import { useQuery...