Reader small image

You're reading from  React Application Architecture for Production

Product typeBook
Published inJan 2023
Reading LevelExpert
PublisherPackt
ISBN-139781801070539
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Alan Alickovic
Alan Alickovic
author image
Alan Alickovic

Alan Alickovic is a software developer, mentor and open source enthusiast from Serbia. He has extensive experience in building scalable applications from startups to large organizations. Besides being an individual contributor he has also been leading teams and mentoring other developers. By the time of this writing, he is working as a senior software engineer at Vroom.
Read more about Alan Alickovic

Right arrow

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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
React Application Architecture for Production
Published in: Jan 2023Publisher: PacktISBN-13: 9781801070539

Author (1)

author image
Alan Alickovic

Alan Alickovic is a software developer, mentor and open source enthusiast from Serbia. He has extensive experience in building scalable applications from startups to large organizations. Besides being an individual contributor he has also been leading teams and mentoring other developers. By the time of this writing, he is working as a senior software engineer at Vroom.
Read more about Alan Alickovic