REST API is one of the most important technologies used to connect mobile applications with servers and databases.
When you build a React Native application, the app usually needs data from a server. REST API provides a standard way for the mobile app to send requests to the server and receive data in response.
API stands for Application Programming Interface.
An API allows two different software applications to communicate with each other.
For example, a React Native mobile application can communicate with a PHP server through an API.
React Native App → API → PHP Server → MySQL
REST stands for Representational State Transfer.
REST is an architectural style used to design web services that communicate using HTTP.
REST commonly uses HTTP methods such as GET, POST, PUT, PATCH and DELETE.
A REST API is an API designed according to REST principles.
It allows applications to communicate with a server using HTTP requests and responses.
For example:
GET https://example.com/api/students
The server can return student information in JSON format.
A mobile application normally does not store all its data directly inside the application.
Instead, the application communicates with a remote server.
REST API provides the communication layer between the mobile application and the server.
React Native
↓
REST API
↓
PHP Server
↓
MySQL
React Native can communicate with REST APIs using technologies such as Fetch API and Axios.
For example, a React Native application can request a list of students from a server.
React Native
↓
GET Request
↓
REST API
↓
MySQL
↓
JSON Response
↓
React Native
REST API communication normally involves a client and a server.
The client sends a request and the server processes the request and returns a response.
In a mobile application, the React Native app acts as the client.
The React Native application is usually the client in a mobile application architecture.
It can request data from the server.
Mobile App
↓
Request
↓
REST API
The client can also send data to the server.
The server receives requests from the mobile application.
The server can validate the request, communicate with the database, perform business logic and return a response.
In our course, we will use PHP for creating the server-side REST API.
A database stores application data.
We will use MySQL as the database in this course.
For example, a student management application may have a students table.
students
----------------
id
name
email
mobile
course
A typical mobile application works through a communication flow.
React Native App
↓
HTTP Request
↓
REST API
↓
PHP Server
↓
MySQL
↓
PHP Server
↓
JSON Response
↓
React Native App
An HTTP request is sent by the client to the server.
A request can contain information such as:
After processing a request, the server sends an HTTP response.
A response commonly contains:
REST APIs commonly return data in JSON format.
JSON stands for JavaScript Object Notation.
It is commonly used to exchange data between a mobile application and a server.
{
"id": 1,
"name": "Rahul",
"course": "React Native"
}
A REST API provides URLs called endpoints.
Example:
https://example.com/api/students
Here, /api/students represents an API endpoint for student resources.
An endpoint is a specific URL through which an application accesses a particular resource.
Examples:
GET /api/students
GET /api/students/10
POST /api/students
PUT /api/students/10
DELETE /api/students/10
GET is generally used to retrieve data from the server.
Example:
GET /api/students
The server can return a list of students.
POST is generally used to send new data to the server.
Example:
POST /api/students
The mobile application can send student information in the request body.
PUT is generally used to update an existing resource.
Example:
PUT /api/students/10
This can update the student whose ID is 10.
DELETE is generally used to remove a resource.
Example:
DELETE /api/students/10
This request can delete the student with ID 10.
CRUD stands for:
REST APIs commonly provide endpoints for all these operations.
Suppose we are developing a student management mobile application.
We may create the following endpoints:
GET /api/students
GET /api/students/5
POST /api/students
PUT /api/students/5
DELETE /api/students/5
PHP can be used to create REST API endpoints.
The PHP API can receive an HTTP request, process it and communicate with MySQL.
React Native
↓
PHP REST API
↓
MySQL
MySQL can store the data used by a REST API.
For example, a student API can read student records from MySQL and return them as JSON.
MySQL Record
↓
PHP API
↓
JSON
↓
React Native
A REST API can be used by applications written in different programming languages.
For example, the server can be written in PHP while the client can be written using React Native.
PHP Server
↑
REST API
↓
React Native
A mobile application can be divided into different layers.
React Native UI
↓
API Service
↓
REST API
↓
PHP Business Logic
↓
MySQL Database
This separation makes the application easier to develop and maintain.
Consider a student management mobile application.
The application may allow users to:
These features can be implemented using REST API endpoints.
In this REST API course, we will gradually learn:
The recommended learning flow is:
REST Fundamentals
↓
HTTP & JSON
↓
Postman
↓
PHP + MySQL API
↓
CRUD API
↓
Authentication & JWT
↓
React Native Fetch
↓
Axios
↓
TypeScript
↓
Complete Mobile App
The main goal of this course is to learn how to create a complete backend REST API and connect it with a React Native mobile application.
By the end of the course, you will be able to create APIs using PHP + MySQL and consume those APIs from React Native + TypeScript.
React Native + TypeScript
↓
Fetch / Axios
↓
REST API
↓
PHP Backend
↓
MySQL
Question: What does REST API provide to a React Native application?