Skip to main content

API Request Anatomy

An API request allows you to retrieve and send data to a data source or server. The API request is formed up of four things:

  1. The endpoint
  2. The method
  3. The headers
  4. The data (or body)

1. Endpoint

Endpoint or route is the URL you request for. It follows this structure:

Syntax

Root Endpoint + Resource + Parameters (Query/Path/Any other)
  • Root Endpoint: The root-endpoint is the starting point of the API you’re requesting. The root-endpoint of Twitter APIs is https://api.twitter.com and Facebook graph API is https://graph.facebook.com/.
  • Resource: /cars, /fruits, /user, /product
  • Parameters: Query, Path, Form or any other type of parameter.

Query parameters consist of key-value pairs which always begin with a question mark (?). Each parameter pair is then separated with an ampersand (&), like this:

?query1=value1&query2=value2

PATH Parameter: required to access the resource E.g. /user/1 (/user/{user_id}) 

# /product/{product_id}
/product/10 

2. HTTP Method

The following are the most popular:

  1. Get (Search for data)
  2. Post (Send data)
  3. Put (Update data)
  4. Patch (Partial Update)
  5. Delete (Delete data)

3. Request Headers

The additional details provided for communication between client and server. Some of the common headers are: 

  • accept-language
  • Accept-Charset
  • Accept-Encoding
  • Authorization
  • Content-Type

4. Request Body 

Also called request data, request message, body parameters or payload. contains the info you want to send to the server. Like for login request you send information like username and password.

{
    "gender": "Male",
    "name": "Harry Potter",
    "email": "hoggwarts@wiz.com",
    "status": "active"
}

Submitted by tgoswami on November 27, 2021

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.