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.
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
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
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.
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.
REST APIs generally organize application data as resources.
Examples include:
/api/students
/api/users
/api/products
REST APIs commonly use URLs that represent resources.
For example:
/api/students
A particular student can be identified using an ID.
/api/students/10
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 |
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
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.
| 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 |
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.
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.
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.
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"
}
]
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.
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.
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
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
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.
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 |
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
REST APIs commonly use HTTP status codes to communicate the result of a request.
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.
A React Native application can send an authentication token when accessing protected REST API endpoints.
React Native
↓
Authorization Token
↓
Protected REST API
↓
PHP
↓
MySQL
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.
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.
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.
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
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 |
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.
Question: Which statement correctly describes the relationship between a Web API and a REST API?