📘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 Method | What It Does | IT Example |
|---|---|---|
| GET | Retrieves information | Get the list of devices connected to a network |
| POST | Creates a new resource | Add a new user to a system |
| PUT | Updates a resource | Change the configuration of a router |
| PATCH | Partially updates a resource | Change only the IP address of a device |
| DELETE | Deletes a resource | Remove a user from the system |
API Documentation – Your Guidebook
Every REST API comes with documentation. Think of it as a manual that tells you:
- The URL (endpoint) you need to contact.
- What HTTP method to use (GET, POST, etc.).
- Headers required (like authentication tokens).
- Request body (the data you need to send if creating or updating something).
- 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:
- Endpoint URL: The address where you send your request.
- Example:
https://api.network.com/devices
- Example:
- HTTP Method: What action you need to perform.
- Example: GET to list devices.
- 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)
- Common headers:
- 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”
}
- Example JSON to add a device: {
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
requestslibrary
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:
- Status Code: Indicates success or failure
200= Success201= Created400= Bad Request401= Unauthorized404= Not Found500= Server Error
- 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
- Always check the HTTP method – GET, POST, PUT, PATCH, DELETE. Using the wrong one may fail the request.
- Always include required headers, especially authentication tokens.
- JSON format is standard for sending data – ensure syntax is correct.
- Follow the endpoint exactly – extra slashes or typos can break the request.
- Read response codes – they tell you if your request worked or why it failed.
Summary for the Exam
To construct a REST API request:
- Read the documentation to know endpoint, method, headers, and body.
- Build the request using the correct HTTP method and data format.
- Send the request using a tool or script.
- 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.
