π 1. π₯ What is a Normal API?
- API (Application Programming Interface) is a generic term for any set of functions or methods that allow applications to communicate with each other.
- It can be:
- Local or remote.
- Can use any protocol (HTTP, TCP, UDP, etc.).
- Not restricted to web-based communication.
-
Examples:
-
Library API: Pythonβs
math.sqrt()
function. -
Database API:
MySQL Connector
for interacting with a database. -
System API: Linux system calls like
read()
orwrite()
. - Hardware API: DirectX for rendering graphics.
-
Library API: Pythonβs
π₯ 2. βοΈ What is a REST API?
- REST (Representational State Transfer) is a specific type of web API.
- It follows the RESTful architecture and uses HTTP methods to interact with resources.
- REST APIs:
- Use stateless communication (each request is independent).
- Use standard HTTP methods:
-
GET
β Retrieve data. -
POST
β Create new data. -
PUT/PATCH
β Update existing data. -
DELETE
β Remove data.
-
- Use JSON or XML for data exchange.
-
Examples:
- GitHub REST API: To access GitHub data over HTTP.
- OpenWeather API: For weather data retrieval.
- Stripe API: For payment processing.
βοΈ 3. Key Differences:
Feature | Normal API | REST API |
---|---|---|
Scope | Generic term for all APIs | Specific type of web API |
Protocol | Uses any protocol (TCP, UDP, etc.) | Uses HTTP/HTTPS only |
State management | Can be stateful or stateless | Stateless by design |
Data format | Any format (binary, JSON, XML) | Mostly JSON or XML |
Methods | Varies (no fixed methods) | Uses standard HTTP methods |
Communication | Local or remote | Web-based (remote) communication |
Example | File System API, Database API | GitHub, Stripe, AWS S3 REST API |
β π₯ Final Takeaway:
- Normal API: A broad term covering all APIs (local, web, database, etc.).
- REST API: A specific type of web API that uses HTTP and follows RESTful principles.
- All REST APIs are APIs, but not all APIs are RESTful. π
Top comments (0)