Lesson 3 of 158 – What is REST?
3%

What is REST?

REST stands for Representational State Transfer. REST is an architectural style used for designing web services and APIs.

REST APIs allow applications such as React Native mobile apps to communicate with servers using standard HTTP requests.

Note: REST is not a programming language or a framework. It is a set of architectural principles used to design APIs.

1. What Does REST Stand For?

REST stands for:

Representational State Transfer

It was introduced as an architectural style for designing networked applications.

2. REST is an Architectural Style

REST is an architectural style, not a programming language.

It provides principles and guidelines for designing APIs that communicate over a network.

For example, PHP can be used to implement a REST API.

3. REST and HTTP

REST APIs commonly use the HTTP protocol for communication.

HTTP provides methods such as:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

4. REST API

A REST API is an API designed using REST principles.

It exposes resources through URLs and uses HTTP methods to perform operations on those resources.


GET /api/students
POST /api/students
PUT /api/students/10
DELETE /api/students/10

5. REST Resources

REST focuses on resources.

A resource can represent an object or collection of data.

Examples:

  • Students
  • Users
  • Products
  • Courses
  • Orders

6. Resource URL

A REST resource is commonly represented using a URL.

For example:


/api/students

This endpoint can represent a collection of students.

7. Individual Resource

A specific resource can be identified using an ID.


/api/students/10

Here, 10 can represent the ID of a particular student.

8. GET in REST

GET is commonly used to retrieve resources.

Example:


GET /api/students

This can return a list of students.

9. POST in REST

POST is commonly used to submit data and create a new resource.

Example:


POST /api/students

The request body can contain the information of a new student.

10. PUT in REST

PUT is commonly used to update an existing resource.

Example:


PUT /api/students/10

This request can update the student with ID 10.

11. PATCH in REST

PATCH is commonly used to partially update an existing resource.

Example:


PATCH /api/students/10

It can be used when only selected fields need to be changed.

12. DELETE in REST

DELETE is commonly used to remove a resource.

Example:


DELETE /api/students/10

This can remove the student whose ID is 10.

13. Statelessness

One important REST principle is statelessness.

Each request should contain the information necessary for the server to process that request.

The server does not rely on previous requests to understand the current request.

14. Stateless Request Example

Suppose a mobile application requests a protected student profile. The request can include an authentication token.


GET /api/profile

Authorization: Bearer TOKEN

The server can use the information in the current request to authenticate and process it.

15. Client-Server Architecture

REST separates the client from the server.


Client
  |
  | HTTP Request
  ↓
Server
  |
  | HTTP Response
  ↓
Client

In our course, React Native will act as the client and PHP will act as the server-side API.

16. Separation of Client and Server

The client and server can be developed separately.

The React Native application can focus on the user interface while the PHP API handles server-side processing and database operations.


React Native
     ↓
REST API
     ↓
PHP
     ↓
MySQL

17. Uniform Interface

REST promotes a consistent way of interacting with resources.

For example, a student resource can be accessed through predictable endpoints.


GET    /api/students
GET    /api/students/5
POST   /api/students
PUT    /api/students/5
DELETE /api/students/5

18. Representation of a Resource

A REST API can return a representation of a resource.

JSON is commonly used for this representation.


{
    "id": 5,
    "name": "Rahul",
    "course": "React Native"
}

The actual database record is not directly exposed to the client.

19. JSON Response

A REST API can return a JSON response containing a collection of resources.


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

React Native can convert this response into JavaScript/TypeScript data and display it.

20. REST and CRUD

REST APIs commonly map HTTP methods to CRUD operations.

Operation HTTP Method
Create POST
Read GET
Update PUT / PATCH
Delete DELETE

21. REST API Example for Students

Suppose our application manages student records.


GET    /api/students
GET    /api/students/1
POST   /api/students
PUT    /api/students/1
PATCH  /api/students/1
DELETE /api/students/1

These endpoints provide a consistent way to work with student resources.

22. REST and React Native

React Native applications can consume REST APIs using Fetch or Axios.

For example:


React Native
      ↓
GET /api/students
      ↓
PHP REST API
      ↓
JSON Response
      ↓
React Native

23. REST and PHP

PHP can process HTTP requests and create REST API endpoints.

For example, a PHP file can receive a request for students, query MySQL and return JSON.


React Native
      ↓
PHP API
      ↓
MySQL
      ↓
JSON

24. REST and MySQL

REST itself does not require MySQL.

However, our projects will use MySQL as the database behind the PHP REST API.


React Native
      ↓
REST API
      ↓
PHP
      ↓
MySQL

25. REST API URL Design

REST APIs generally use resource-oriented URLs.

For example:


/api/students
/api/users
/api/products
/api/orders

A specific resource can be identified using an ID.


/api/students/10
/api/users/5
/api/products/20

26. REST API Status Codes

REST APIs use HTTP status codes to communicate the result of a request.

  • 200 – Successful request
  • 201 – Resource created
  • 400 – Bad request
  • 401 – Unauthorized
  • 404 – Resource not found
  • 500 – Server error

We will study HTTP status codes in detail in a later lesson.

27. REST API and Security

REST APIs may contain sensitive application data, so security is important.

Our course will later cover topics such as:

  • Authentication
  • Password hashing
  • JWT
  • Protected API routes
  • Input validation
  • SQL injection prevention

28. REST API Example Flow

Consider a React Native student application.


User taps "View Students"
          ↓
React Native sends GET request
          ↓
GET /api/students
          ↓
PHP processes request
          ↓
PHP queries MySQL
          ↓
MySQL returns records
          ↓
PHP creates JSON response
          ↓
React Native displays students

29. Main REST Principles

Important REST concepts include:

  • Client-server architecture
  • Stateless communication
  • Uniform interface
  • Resource-based design
  • Representation of resources
  • Use of standard HTTP methods

These concepts help us design organized and predictable APIs.

30. REST in Our Mobile App Course

REST will be the foundation for connecting our React Native mobile applications with the backend.


React Native + TypeScript
           ↓
       Fetch / Axios
           ↓
        REST API
           ↓
       PHP Backend
           ↓
        MySQL

In the upcoming lessons, we will learn HTTP methods, API endpoints, JSON, Postman, PHP REST API development and eventually connect the API to React Native.

📌 Key Points

  • REST stands for Representational State Transfer.
  • REST is an architectural style.
  • REST APIs commonly use HTTP.
  • REST APIs work with resources.
  • URLs are used to identify resources.
  • GET is commonly used to read data.
  • POST is commonly used to create data.
  • PUT and PATCH are commonly used for updates.
  • DELETE is commonly used to remove data.
  • REST promotes stateless communication.
  • REST separates the client and server.
  • JSON is commonly used to represent API data.
  • REST APIs are useful for React Native applications.
  • Our course will use PHP and MySQL for the backend.

🧠 Quick Quiz

Question: What does REST stand for?