Lesson 2 of 158 – What is an API?
2%

What is an API?

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.

Note: In this course, we will use APIs to connect React Native applications with a PHP and MySQL backend.

1. Meaning of API

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

2. Why Do We Need APIs?

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.

3. API as a Communication Layer

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.

4. API in Mobile Applications

A React Native application can use an API to perform operations such as:

  • Login
  • Registration
  • Fetching data
  • Adding data
  • Updating data
  • Deleting data
  • Searching data

5. Simple API Example

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.

6. API Request

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.

7. API Response

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"
}

8. Client

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

9. 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

10. Database

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

11. API Communication Flow

The basic communication flow can be represented as follows:


React Native
     ↓
API Request
     ↓
PHP REST API
     ↓
MySQL
     ↓
PHP REST API
     ↓
JSON Response
     ↓
React Native

12. API and HTTP

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.

13. API and JSON

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.

14. API Endpoint

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.

15. API Resource

A resource represents data or functionality that can be accessed through an API.

Examples of resources include:

  • Students
  • Users
  • Products
  • Courses
  • Orders
  • Payments

16. GET API Example

A GET request is commonly used to retrieve information.


GET /api/students

The server may return:


[
    {
        "id": 1,
        "name": "Rahul"
    },
    {
        "id": 2,
        "name": "Amit"
    }
]

17. POST API Example

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"
}

18. PUT API Example

PUT can be used to update an existing resource.


PUT /api/students/1

The server can update the student whose ID is 1.

19. DELETE API Example

DELETE can be used to remove a resource.


DELETE /api/students/1

The server can remove the student with ID 1.

20. API and CRUD

CRUD represents four common operations:

  • Create – Add new information
  • Read – Retrieve information
  • Update – Modify information
  • Delete – Remove information

REST APIs commonly provide endpoints that support these operations.

21. API Authentication

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.

22. API for Login

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.

23. API for Registration

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.

24. API for Searching Data

APIs can also provide search functionality.

For example:


GET /api/students?search=Rahul

The server can process the search parameter and return matching records.

25. API for Mobile App Data

A mobile application can request many types of data through APIs.

  • User profiles
  • Student records
  • Products
  • Orders
  • Courses
  • Notifications
  • Reports

The server sends the required data to the mobile application.

26. API Hides Database Details

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

27. API Can Be Used by Multiple Applications

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.

28. API Technologies in This Course

We will use several technologies while learning REST APIs.

  • PHP – Backend API development
  • MySQL – Database
  • Postman – API testing
  • JSON – Data exchange
  • React Native – Mobile application
  • TypeScript – Type-safe mobile development
  • Fetch – API requests
  • Axios – API requests

29. Real-World API Example

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.

30. API Learning Summary

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.

📌 Key Points

  • API stands for Application Programming Interface.
  • An API allows software applications to communicate.
  • React Native can act as an API client.
  • PHP can be used to create server-side APIs.
  • MySQL can store data used by an API.
  • HTTP is commonly used for web API communication.
  • JSON is commonly used to exchange API data.
  • GET retrieves data.
  • POST commonly creates or submits data.
  • PUT commonly updates data.
  • DELETE commonly removes data.
  • APIs can provide authentication and protected resources.
  • REST APIs are useful for building mobile applications.

🧠 Quick Quiz

Question: What is the primary purpose of an API?