API stands for Application Programming Interface. An API is a way that allows two different software applications to communicate with each other.
In mobile application development, an API is commonly used to connect a mobile application with a server and database.
API means Application Programming Interface.
It provides a defined way for one application to communicate with another application or service.
Application A
↓
API
↓
Application B
Applications often need data or services that are provided by another system.
Instead of directly accessing another application's internal code or database, an application can communicate through an API.
For example, a mobile app can request student information from a server through an API.
An API acts as a communication layer between a client and a server.
React Native App
↓
API
↓
Server
↓
Database
The mobile application does not need to directly communicate with the database.
A React Native application can use an API to perform operations such as:
Suppose a mobile application needs a list of students.
The React Native application can send a request to an API.
GET /api/students
The server can return student information.
An API request is a message sent by the client to the server.
For example:
GET https://example.com/api/students
The request tells the server which resource the client wants to access.
After receiving a request, the server processes it and sends a response.
For example, the response may contain student information in JSON format.
{
"id": 1,
"name": "Rahul",
"course": "React Native"
}
The client is the application that makes the API request.
In our mobile application course, the React Native application acts as the client.
React Native
↓
Request
↓
Server
The server receives the request from the client and performs the required processing.
In our REST API course, we will use PHP to create server-side APIs.
React Native
↓
PHP API
↓
MySQL
A database stores the application's data.
We will use MySQL in our PHP REST API projects.
For example, a database may contain a students table.
students
----------------
id
name
email
mobile
course
The basic communication flow can be represented as follows:
React Native
↓
API Request
↓
PHP REST API
↓
MySQL
↓
PHP REST API
↓
JSON Response
↓
React Native
Web APIs commonly communicate using the HTTP protocol.
HTTP provides methods that can be used for different operations.
GET
POST
PUT
PATCH
DELETE
We will study these methods in detail in upcoming lessons.
JSON is commonly used for exchanging structured data between a client and server.
Example:
{
"id": 101,
"name": "Amit",
"email": "amit@example.com"
}
React Native can read this JSON response and display the data.
An API endpoint is a specific URL used to access a particular resource.
Example:
https://example.com/api/students
Here, /api/students can represent the students resource.
A resource represents data or functionality that can be accessed through an API.
Examples of resources include:
A GET request is commonly used to retrieve information.
GET /api/students
The server may return:
[
{
"id": 1,
"name": "Rahul"
},
{
"id": 2,
"name": "Amit"
}
]
A POST request can be used to send new data to the server.
POST /api/students
The request body might contain:
{
"name": "Rahul",
"email": "rahul@example.com"
}
PUT can be used to update an existing resource.
PUT /api/students/1
The server can update the student whose ID is 1.
DELETE can be used to remove a resource.
DELETE /api/students/1
The server can remove the student with ID 1.
CRUD represents four common operations:
REST APIs commonly provide endpoints that support these operations.
Some APIs require users to authenticate before accessing protected data.
For example, a mobile application may send login information to a login API.
React Native
↓
Login API
↓
PHP
↓
MySQL
Authentication and JWT will be covered later in this course.
A login API can receive user credentials and verify them on the server.
For example:
POST /api/login
The mobile application can send an email and password in the request body.
A registration API can receive information about a new user and store it in the database.
Example:
POST /api/register
The PHP API can validate the submitted data and insert the record into MySQL.
APIs can also provide search functionality.
For example:
GET /api/students?search=Rahul
The server can process the search parameter and return matching records.
A mobile application can request many types of data through APIs.
The server sends the required data to the mobile application.
A mobile application normally should not directly connect to the MySQL database over the internet.
Instead, the application communicates with the server through an API.
Wrong Approach:
React Native → MySQL
Common Approach:
React Native → API → MySQL
One API can serve multiple client applications.
REST API
/ | \
/ | \
↓ ↓ ↓
Android React Web
Native
For example, the same backend can provide data to a mobile app and a web application.
We will use several technologies while learning REST APIs.
Consider a student management mobile application.
The React Native application can communicate with a PHP REST API using endpoints such as:
POST /api/login
GET /api/students
GET /api/students/10
POST /api/students
PUT /api/students/10
DELETE /api/students/10
This allows the mobile application to perform complete student management operations.
An API provides a structured way for applications to communicate. In our mobile application development course, the API will act as the connection between React Native and the PHP/MySQL backend.
React Native + TypeScript
↓
REST API
↓
PHP Backend
↓
MySQL Database
Understanding this communication flow is essential before creating our own REST APIs.
Question: What is the primary purpose of an API?