Construct a REST API request to accomplish a task given API documentation

📘Cisco DevNet Associate (200-901 DEVASC)


Understanding REST APIs

REST API stands for Representational State Transfer Application Programming Interface.

In simpler words:

  • It’s a way for two software systems to communicate over the Internet.
  • You send a request to a server (like asking a server for information), and the server responds with the data you asked for.

For the exam, you need to understand that REST APIs use HTTP methods to perform tasks:

HTTP MethodWhat It DoesIT Example
GETRetrieves informationGet the list of devices connected to a network
POSTCreates a new resourceAdd a new user to a system
PUTUpdates a resourceChange the configuration of a router
PATCHPartially updates a resourceChange only the IP address of a device
DELETEDeletes a resourceRemove a user from the system

API Documentation – Your Guidebook

Every REST API comes with documentation. Think of it as a manual that tells you:

  1. The URL (endpoint) you need to contact.
  2. What HTTP method to use (GET, POST, etc.).
  3. Headers required (like authentication tokens).
  4. Request body (the data you need to send if creating or updating something).
  5. Response format (usually JSON) and possible status codes.

Step 1: Read the API Documentation

When constructing a request, start by identifying these key points in the documentation:

  1. Endpoint URL: The address where you send your request.
    • Example: https://api.network.com/devices
  2. HTTP Method: What action you need to perform.
    • Example: GET to list devices.
  3. Headers: Extra information like authentication.
    • Common headers:
      • Authorization: Bearer <token> (tells the server who you are)
      • Content-Type: application/json (tells the server the format of your data)
  4. Request Body (if required): The data to send when creating or updating resources.
    • Example JSON to add a device: {
      “name”: “Switch-01”,
      “ip”: “192.168.1.10”,
      “location”: “Data Center 1”
      }

Step 2: Construct the Request

Use the information from the documentation to construct your request. For example:

  • GET request to list devices: GET /devices HTTP/1.1
    Host: api.network.com
    Authorization: Bearer <your_token>
  • POST request to create a new device: POST /devices HTTP/1.1
    Host: api.network.com
    Authorization: Bearer <your_token>
    Content-Type: application/json{
    “name”: “Switch-01”,
    “ip”: “192.168.1.10”,
    “location”: “Data Center 1”
    }

Step 3: Send the Request

You can send requests in multiple ways:

  • Command-line tools: like curl
  • API testing tools: like Postman
  • Scripts in Python: using requests library

Example using curl (GET request):

curl -X GET https://api.network.com/devices \
-H "Authorization: Bearer <your_token>"

Example using Python:

import requestsurl = "https://api.network.com/devices"
headers = {"Authorization": "Bearer <your_token>"}response = requests.get(url, headers=headers)
print(response.json())

Step 4: Handle the Response

Every API request gives a response with:

  1. Status Code: Indicates success or failure
    • 200 = Success
    • 201 = Created
    • 400 = Bad Request
    • 401 = Unauthorized
    • 404 = Not Found
    • 500 = Server Error
  2. Response Body: Usually JSON format with the data you requested.
    Example: [
    {
    “id”: 1,
    “name”: “Switch-01”,
    “ip”: “192.168.1.10”,
    “location”: “Data Center 1”
    },
    {
    “id”: 2,
    “name”: “Router-01”,
    “ip”: “192.168.1.1”,
    “location”: “Data Center 2”
    }
    ]

Step 5: Common Tips for Exam

  1. Always check the HTTP method – GET, POST, PUT, PATCH, DELETE. Using the wrong one may fail the request.
  2. Always include required headers, especially authentication tokens.
  3. JSON format is standard for sending data – ensure syntax is correct.
  4. Follow the endpoint exactly – extra slashes or typos can break the request.
  5. Read response codes – they tell you if your request worked or why it failed.

Summary for the Exam

To construct a REST API request:

  1. Read the documentation to know endpoint, method, headers, and body.
  2. Build the request using the correct HTTP method and data format.
  3. Send the request using a tool or script.
  4. Check the response for status code and returned data.

This is a skill you need to demonstrate on the exam, often by reading an API spec and identifying the correct way to send a request.

Buy Me a Coffee