An application programming interface (API) is a particular set of rules (‘code’) and specifications that software programs can follow to communicate with each other. It serves as an interface between different software programs and facilitates their interaction, similar to the way the user interface facilitates interaction between humans and computers.
Types of Web service API:
GET: Retrieve information. GET requests must be safe and idempotent, meaning regardless of how many times it repeats with the same parameters, the results are the same. They can have side effects, but the user doesn’t expect them, so they cannot be critical to the operation of the system. Requests can also be partial or conditional.
Retrieve an address with an ID of 1: GET /addresses/1
POST: Request that the resource at the URI does something with the provided entity. Often POST is used to create a new entity, but it can also be used to update an entity.
Create a new address: POST /addresses
PUT: Store an entity at a URI. PUT can create a new entity or update an existing one. A PUT request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.
Modify the address with an ID of 1: PUT /addresses/1
Note: PUT replaces an existing entity. If only a subset of data elements is provided, the rest will be replaced with empty or null.
PATCH: Update only the specified fields of an entity at a URI. A PATCH request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.
DELETE: Request that a resource is removed; however, the resource does not have to be removed immediately. It could be an asynchronous or long-running request.
Delete an address with an ID of 1: DELETE /addresses/1