API Automation 101

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!

  1. GET: Retrieve a representation of a resource’s contents.
  2. POST: Submit an entity to be processed by the resource identified by the URI.
  3. PUT: Replace all current representations of the target resource with the request payload.
  4. PATCH: Apply partial modifications to a resource.
  5. DELETE: Delete a resource.
  6. HEAD: Retrieve the headers of a resource without the body.
  7. OPTIONS: Retrieve the allowed methods and headers of a resource.
  8. CONNECT: Establish a network connection to a URI using a proxy.
  9. 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"
}

Tools used to test APIs

Libraries used for APIs Automation

Scroll to Top