What is an API?
API stands for
Application
Programming
Interface. It's an interface responsible for communication / data transfer between two different software applications.
There are mainly two types of Web Services:
- REST (Representational State Transfer)
- SOAP (Simple Object Access Protocol)
REST stands for Representational State Transfer, which provides an ability of exchanging information between the the applications. These web services provide a predefined set of stateless operations and allow requesting applications to access and manipulate the data.
SOAP stands for
Simple
Object
Access
Protocol, which allows exchange of meaningful information between the applications using XML. It helps in exchanging structured information.
HTTP Methods
HTTP stands for Hyper Text Transfer Protocol is an application protocol for distributed and collaborative information systems.
HTTP defines some set of methods to indicate the expected action to be performed for a given resource. Each of them implement a different logic, but some common characteristics are shared by group of them. eg; a request can be idempotent or non-idempotent.
GET
GET method is used when we need to retrieve the data. For simple understanding, it's like a Select command in SQL.This request doesn't result in modification of the data. If the request is successful, the status code of 200(OK) is received along the data in a particular JSON or XML format. This method is idempotent, i.e no matter how many times you make the request, there won't be any change in the data.
POST
POST method is used when we need to make manipulation of the data. Mostly, it is used to create a resource. When this request is made, a new resource gets created and if it's a successful requests a status code of 201(CREATED) is received. This method is non-idempotent, i.e this may result in duplicates or errors if called more than once.
PUT
PUT method is used when we need to make manipulation of the data. Mostly, it is used to update a existing resource. It maybe used to create a resource is request is made from client side. When this request is made, a new resource gets created and if it's a successful requests a status code of 201(CREATED) is received. This method is idempotent, i.e no matter how many times you make the request, there won't be any change in the data.
DELETE
- DELETE method is used to delete a resource. On a successful request, a status code of 200(OK) is received. This method is also idempotent as if a resource is deleted once it cannot affect it no matter how many times the request is made.
HTTP Response Codes
HTTP response codes fall under following categories:
1xx - Response code series starts with '1' are Informational codes.
2xx - Response code series starts with '2' are Success codes
3xx - Response code series starts with '3' are Redirection codes
4xx - Response code series starts with '4' are Client side error codes
5xx - Response code series starts with '5' are Server side error codes