Definition - API stands for Application Programming Interface and in simple terms it is a layer between the frontend and the backend / Database.
It is a application which does not have any user interface and only returns and accepts data from the database and frontend applications respectively.
Eg - https://reqres.in/api/users?page=1 is a API which returns a array of objects with dummy information about people. Like so -
There are some rules that a developer need to follow while building a API. Depending on these rules, we can have differnet types of API.
And if a API follows these rules ,Then it is called a REST API -
Although ,there are different types of APIs for eg - SOAP, The REST APIs are by far the most popular choise among developers.
An HTTP request is made by a client, to a named host, which is located on a server. The aim of the request is to access a resource on the server. To make the request, the client uses components of a URL (Uniform Resource Locator), which includes the information needed to access the resource.
There are different types of HTTP requests -
GET - The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
HEAD - The HEAD method asks for a response identical to a GET request, but without the response body.
POST - The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.
PUT - The PUT method replaces all current representations of the target resource with the request payload.
DELETE - The DELETE method deletes the specified resource.
CONNECT - The CONNECT method establishes a tunnel to the server identified by the target resource.
OPTIONS - The OPTIONS method describes the communication options for the target resource.
TRACE - The TRACE method performs a message loop-back test along the path to the target resource.
PATCH - The PATCH method applies partial modifications to a resource.
There are several in-built and external javascript packages that help you to make HTTP requests to APIs on different routes. Some of these are -
There are many more.
We have covered what APIs are and when to use them in a react application.
APIs are part of back-end engineering and that's why we covered only the most important topics. But , in-fact they are a very vast topic and i suggest you to go through the links in the refferences section for better understanding.