An API (Application Programming Interface), or an interface for programming applications, allows developers to use ready-made blocks to build an application. In the case of web applications, the API can give data in a format other than standard HTML, making it convenient to use when writing your own applications.
Based on the above, we can distinguish two existing components tied to the web API: server and client. In this case, we consider the server to be an abstract machine on the network that can receive an HTTP request, process it and return the correct response. The physical essence and internal architecture of the server are absolutely not important, whether it be a regular laptop or a big cluster of industrial servers. it doesn’t matter what technology is responsible for processing the request, Apache or Windows IIS, which code, PHP, Python or C#, processes it and forms the answer, which data storage is used: PostgreSQL, MS SQL or MongoDB. The main thing is that the server responds to the main rule – to hear, understand and respond.
The client can be anything that can generate and send a HTTP request and there are several situations in which we need to create a Web API for our own lovingly written and refactored application.
Using a Web API allows you to expand the capabilities of the program, easily accompany various versions of the services provided and in terms of placement in the cloud, it can easily be expanded to provide better performance.
Although JSON-Pure API are becoming more and more popular, the most common standard for Web API is REST.
REST (Representational state transfer) was originally created as a simple and unambiguous interface for managing data, which involved only a few basic operations with server: data extraction (GET), saving (POST), changing (PUT / PATCH) and deleting (DELETE). In addition, REST has a number of architectural principles that are strongly recommended to be observed when developing:
*Server independence from client
*The independence of the storage format of the data transfer format
*Uniqueness of resource addresses
*Visibility of the responses for all of the metadata necessary for using the API e.g. error messages, the total number of records in the collection for the correct display of page navigation etc.
Creating a complete API for applications is only half the business. For correct use of the API, you must provide the necessary documentation to service users. There are several libraries that allow developers to automatically generate the documentation and place it in the same hosting as the API itself e.g. Swagger. Another solution would be creating an API framework that clients can use for communication with an API service. For large API services like e.g. GitHub, Twitter have frameworks written in different programming languages to allow as many clients as possible to use their API easily.
Using a Web API allows you to expand the capabilities of the program, easily accompany various versions of the services provided and in terms of placement in the cloud, it can easily be expanded to provide better performance.