What is API?
This note provides an overview of key concepts related to APIs, HTTP, REST, headers, stateless protocols, CRUD operations, JSON, cacheability, layered systems, and Curl.
API
- Definition: API stands for Application Programming Interface. It refers to a set of rules and protocols that allow different software applications to communicate with each other.
- Types of APIs:
- Framework APIs: APIs provided by frameworks that allow developers to extend and customize the functionality of the framework.
- Package and Library APIs: APIs provided by packages and libraries that solve common problems and provide reusable code.
- Remote APIs: APIs like REST and GraphQL that allow communication with remote servers over a network.
- Web-based APIs: APIs that are accessed through web protocols, typically using HTTP.
HTTP and Verbs
- HTTP: HTTP stands for Hypertext Transfer Protocol. It is a protocol that defines the expectations for communication between clients and servers.
- HTTP Verbs:
- GET: Used to receive information and retrieve data from the server (read operation).
- POST: Used to submit data to the server and receive a response (create operation).
- PUT: Used to update existing data on the server.
- PATCH: Used to partially update existing data on the server.
- DELETE: Used to delete specific resources from the server.
Stateless Protocol
- Definition: A stateless protocol is a type of communication protocol in which each transaction between a client and a server is independent and self-contained. The server does not retain any information about the client’s previous interactions or the current state of the client.
- Advantages: Stateless protocols are scalable, lightweight, and promote fault tolerance.
- Limitations: They are not suitable for scenarios that require maintaining a continuous session or context across multiple requests.
Headers
- Definition: Headers are specific sections of data that precede the main content or payload of a message or packet.
- Function: Headers provide important information and metadata about the message, facilitating its interpretation and processing by the receiving entity.
- Examples: In the context of HTTP, headers include fields like “Host,” “User-Agent,” and “Content-Type.”
REST and CRUD
- REST: REST stands for Representational State Transfer. It is an architectural style for designing networked applications and APIs.
- CRUD: CRUD stands for Create, Read, Update, and Delete, which are the basic operations performed on data.
- Relationship: RESTful APIs map the CRUD operations to appropriate HTTP methods (POST, GET, PUT/PATCH, DELETE) to provide a consistent and intuitive interface for interacting with resources.
JSON
- Definition: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is commonly used for structuring data in APIs and exchanging information between a client and a server.
Layered System
- Definition: A layered system is an architectural style where components are organized in layers, and each layer has specific responsibilities. Communication between layers is well-defined and follows certain protocols.
Cacheability
- Definition: Cacheability refers to the capability of storing and reusing previously obtained responses from a server. Caching can improve performance by reducing the need for repeated requests to the server.
Curl
- Definition: Curl is a command-line tool and library used for making requests to web servers and transferring data using various protocols such as HTTP, HTTPS, FTP, SMTP, and more.
- Use Cases: Curl is used for sending HTTP requests, testing APIs, downloading/uploading files, scripting and automation, and debugging network connectivity issues.
What is API?
https://lilaliang.github.io/2023/06/01/2/