Open YuezhenQin opened 4 months ago
tmp
The invention and evolution of different API types are driven by the need to efficiently manage communication between different software systems, often across the internet.
These APIs use SOAP (Simple Object Access Protocol). The client and server exchange messages using XML.
These APIs are called Remote Procedure Calls. The client completes a function or procedure on the server, and the server sends the result back to the client.
A WebSocket API supports two-way communication between client and server. The server can send callback messages to connected clients, making it more efficient than REST API.
The client sends requests to the server as data. The server uses this client input to start internal functions and returns output data back to the client.
REST stands for “Representational State Transfer”. It is a set of rules that developers follow when they create their API. One of these rules states that you should be able to get a piece of data (called a resource) when you link to a specific URL.
Each URL is called a request while the data sent back to you is called a response.
source: https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/
REST is a set of architectural constraints, not a protocol or a standard. API developers can implement REST in a variety of ways.
When a client request is made via a RESTful API, it transfers a representation of the state of the resource to the requester or endpoint. This information, or representation, is delivered in one of several formats via HTTP: JSON (Javascript Object Notation), HTML, XLT, Python, PHP, or plain text. JSON is the most generally popular file format to use because, despite its name, it’s language-agnostic, as well as readable by both humans and machines.
Something else to keep in mind: Headers and parameters are also important in the HTTP methods of a RESTful API HTTP request, as they contain important identifier information as to the request's metadata, authorization, uniform resource identifier (URI), caching, cookies, and more. There are request headers and response headers, each with their own HTTP connection information and status codes.
In order for an API to be considered RESTful, it has to conform to these criteria:
A client-server architecture made up of clients, servers, and resources, with requests managed through HTTP. Stateless client-server communication, meaning no client information is stored between get requests and each request is separate and unconnected. Cacheable data that streamlines client-server interactions. A uniform interface between components so that information is transferred in a standard form. This requires that: resources requested are identifiable and separate from the representations sent to the client. resources can be manipulated by the client via the representation they receive because the representation contains enough information to do so. self-descriptive messages returned to the client have enough information to describe how the client should process it. hypertext/hypermedia is available, meaning that after accessing a resource the client should be able to use hyperlinks to find all other currently available actions they can take. A layered system that organizes each type of server (those responsible for security, load-balancing, etc.) involved the retrieval of requested information into hierarchies, invisible to the client. Code-on-demand (optional): the ability to send executable code from the server to the client when requested, extending client functionality. Though the REST API has these criteria to conform to, it is still considered easier to use than a prescribed protocol like SOAP (Simple Object Access Protocol), which has specific requirements like XML messaging, and built-in security and transaction compliance that make it slower and heavier.
In contrast, REST is a set of guidelines that can be implemented as needed, making REST APIs faster and more lightweight, with increased scalablity—perfect for Internet of Things (IoT) and mobile app development.
What is an API?
An API is an application programming interface. It enable two program to communicate with each other.
What does API stand for?
"Application" refers to any program with a distinct function.
"Interface" can be thought of as a contract of service between two applications. This contract defines how the two communicate with each other using requests and responses. API documentation contains information on how developers are to structure those requests and responses.
The developer creates the API on the server and allows the client to talk to it.
ref: https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/