Lesson 4 of 158 – REST API vs Web API
4%

REST API vs Web API

REST API and Web API are closely related terms used in web and application development. A Web API is a broad term for an API that can be accessed over the web, while REST API refers to an API designed according to REST architectural principles.

Understanding this difference is useful when developing React Native applications because mobile apps commonly communicate with backend services through web APIs.

Note: REST is an architectural style. A REST API is a Web API that follows REST principles. Not every Web API necessarily follows REST principles.

1. What is a Web API?

A Web API is an API that can be accessed over a network, typically using web technologies such as HTTP.

It allows applications to communicate with a server or service.


Mobile App
     ↓
   Web API
     ↓
  Server

2. What is a REST API?

A REST API is a Web API designed according to REST architectural principles.

REST commonly uses resources, HTTP methods, stateless communication and resource-oriented URLs.


React Native
      ↓
   REST API
      ↓
   Server

3. Web API is a Broad Term

The term Web API can describe many different API designs.

A Web API may use different approaches for organizing endpoints, requests and responses.

REST is one common architectural approach for designing Web APIs.

4. REST is an Architectural Style

REST is not a programming language or a specific software package.

It provides architectural principles that can be followed when designing a Web API.

These principles help create APIs that are organized and predictable.

5. REST API Uses Resources

REST APIs generally organize application data as resources.

Examples include:

  • Users
  • Students
  • Products
  • Courses
  • Orders

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

6. Resource-Based URLs

REST APIs commonly use URLs that represent resources.

For example:


/api/students

A particular student can be identified using an ID.


/api/students/10

7. HTTP Methods in REST

REST APIs commonly use HTTP methods according to the operation being performed.

Method Common Purpose
GET Retrieve data
POST Create or submit data
PUT Update a resource
PATCH Partially update a resource
DELETE Delete a resource

8. Web API and HTTP

Web APIs commonly use HTTP or HTTPS for communication.

A client sends an HTTP request and the server returns an HTTP response.


Client
  ↓
HTTP Request
  ↓
Web API
  ↓
HTTP Response
  ↓
Client

9. REST API and HTTP

REST APIs also commonly use HTTP for communication.

The HTTP method indicates the intended operation on a resource.


GET /api/students

This request can be used to retrieve the students resource.

10. REST API vs Web API

Feature Web API REST API
Meaning Broad term for web-accessible APIs API designed using REST principles
Resources Depends on design Usually resource-oriented
HTTP Commonly used Commonly used
REST Principles Not required Followed in the design
Mobile Usage Possible Very common

11. Stateless Communication

Statelessness is an important REST principle.

Each request should contain the information needed by the server to process that request.

The server should not need to depend on the state of a previous request to understand the current request.

12. Web API Does Not Automatically Mean REST

Calling something a Web API does not automatically mean that it follows all REST principles.

Web API describes how an API is accessed over the web, while REST describes an architectural approach for designing APIs.

Important: Do not treat the terms "Web API" and "REST API" as completely interchangeable in every context.

13. JSON Responses

Many modern Web APIs and REST APIs use JSON for exchanging structured data.


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

React Native can receive this response and use the data inside the application.

14. REST API Example

Suppose we have a student management application.


GET /api/students

The API can return a list of students as JSON.


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

15. Web API Example

A Web API can expose application functionality through HTTP endpoints.

The exact URL design and communication pattern depends on how the API was designed.


https://example.com/api/students

If the API follows REST principles, it can also be described as a REST API.

16. React Native and Web APIs

React Native applications can consume Web APIs.

For example, a mobile application can use the Fetch API to request data from a server.


fetch("https://example.com/api/students")

The response can then be converted into JSON.

17. React Native and REST APIs

REST APIs are especially useful for mobile applications because resources and operations can be represented using standard HTTP requests.


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

18. PHP Web API

PHP can be used to build Web APIs.

For example, a PHP script can receive an HTTP request, communicate with MySQL and return JSON.


React Native
      ↓
PHP Web API
      ↓
MySQL
      ↓
JSON Response

19. PHP REST API

A PHP API can be designed according to REST principles.

For example:


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

This resource-oriented design is commonly used for CRUD operations.

20. CRUD and REST

REST APIs commonly map CRUD operations to HTTP methods.

CRUD HTTP Method Example
Create POST /api/students
Read GET /api/students
Update PUT / PATCH /api/students/10
Delete DELETE /api/students/10

21. URL Design Comparison

A resource-oriented REST design commonly uses URLs such as:


/api/students
/api/students/10

The HTTP method tells the server what operation is being requested.


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

22. API Response Status Codes

REST APIs commonly 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

23. Authentication in Web APIs

Web APIs can implement authentication to protect private resources.

A client may provide credentials or an authentication token with its request.


Authorization: Bearer TOKEN

JWT-based authentication will be covered later in this course.

24. REST API and Mobile Authentication

A React Native application can send an authentication token when accessing protected REST API endpoints.


React Native
      ↓
Authorization Token
      ↓
Protected REST API
      ↓
PHP
      ↓
MySQL

25. REST API vs Web API – Simple Example

Think of Web API as the broader category and REST API as a particular architectural approach within that category.


Web APIs
   |
   └── REST-style APIs

This is a useful way to remember the relationship between the two terms.

26. Why Use REST for Mobile Apps?

REST-style APIs are commonly used in mobile application development because they work well with HTTP-based communication and provide a clear resource-oriented structure.

They can be consumed by React Native applications using Fetch or Axios.

27. REST API Architecture for Our Course

Our mobile application architecture will follow this general structure:


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

This architecture allows the mobile application and backend to work as separate parts of the system.

28. When You See "Web API"

When you see the term Web API, think of an API accessible through web technologies.

When you see REST API, think of an API designed around REST principles and resource-oriented communication.


Web API
   ↓
Web-accessible API

REST API
   ↓
Web API designed using REST principles

29. Important Difference

The most important difference is the level of meaning:

Term Meaning
Web API A broad term for APIs exposed through web technologies
REST API A Web API designed according to REST architectural principles

30. Final Comparison

A Web API and a REST API are related concepts, but they are not exactly the same term.

A Web API describes a web-accessible API in broad terms. A REST API uses REST principles to organize resources, HTTP operations and communication.


React Native
     ↓
  Web API
     ↓
REST-style API
     ↓
   PHP
     ↓
  MySQL

For our course, we will focus on building REST APIs with PHP and MySQL and consuming them from React Native with TypeScript.

📌 Key Points

  • Web API is a broad term for APIs accessible through web technologies.
  • REST API is an API designed according to REST principles.
  • REST is an architectural style.
  • REST commonly uses HTTP methods.
  • REST APIs are generally resource-oriented.
  • REST commonly uses resource-based URLs.
  • REST promotes stateless communication.
  • JSON is commonly used for API data exchange.
  • PHP can be used to build REST APIs.
  • MySQL can be used as the database behind a PHP REST API.
  • React Native can consume REST APIs using Fetch or Axios.
  • A Web API does not automatically mean that it follows REST principles.

🧠 Quick Quiz

Question: Which statement correctly describes the relationship between a Web API and a REST API?