What is APIs?
- In simple terms, when two systems need to communicate with each other, the way how they interact is by using API.
What is REST API?
- Representational State Transfer API (REST)
- REST uses HTTP protocol to transfer data.
- RESTful APIs work by sending HTTP requests to a server, which then sends back a response.
- Four main HTTP methods to perform CRUD (create,read,update,delete)
- GET requests are used to retrieve data from the server.
- POST requests are used to submit new data to the server.
- PUT requests are used to update existing data on the server.
- DELETE requests are used to delete data from the server.
- The principle of REST
- Statelessness – each request is unique and doesn’t require another request context
- Client-Server – request and response architecture using client-server model
- Cacheable – response from the server can be cached on the client side to improve the performance
- Layered System – the architecture is divided into layers, with each layer providing a specific service.
HTTP verbs!
- GET: Retrieve a representation of a resource’s contents.
- POST: Submit an entity to be processed by the resource identified by the URI.
- PUT: Replace all current representations of the target resource with the request payload.
- PATCH: Apply partial modifications to a resource.
- DELETE: Delete a resource.
- HEAD: Retrieve the headers of a resource without the body.
- OPTIONS: Retrieve the allowed methods and headers of a resource.
- CONNECT: Establish a network connection to a URI using a proxy.
- TRACE: Retrieve a diagnostic trace of the request-response chain.
Rest API Request
Rest API Response
What is API automation?
- API(Application Program Interface) automation refers to the process of automating the testing and validation of API.
- This can include creating automated test scripts that send various requests to an API and then validating the response received.
- API automation helps to validate the API functionality working as expected
- Helps to perform regression testing when changes are made to the API.
Sample Request
POST /api/v1/create/users HTTP/1.1 Host: 63896823c5356b25a2ff9df7.mockapi.io Content-Type: application/json Content-Length: 91 { "requestId": "123121", "items": "prem", "count": "1", "anyKey": "kumar" }
Sample Response
Response Code : 201 – Created
{ "createdAt": "2023-01-15T14:52:35.382Z", "name": "Lucille Stoltenberg", "avatar": "https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/151.jpg", "id": "60", "requestId": "123121", "items": "prem", "count": "1", "anyKey": "kumar" }