package
0.0.0-20241227225632-9a01049847fc
Repository: https://github.com/alarmfox/dtlab.git
Documentation: pkg.go.dev
# README
REST API Lab Guide
Introduction
Welcome to the REST API Lab! In this lab, you will learn how to interact with a REST API using Postman. Follow the instructions below to set up Postman and complete the lab activities.
Prerequisites
Before you begin, make sure you have the following:
- Postman installed on your computer
- Basic knowledge of HTTP methods (GET, POST, DELETE, PUT)
- Basic understanding of REST APIs and JSON
Installing Postman
Follow the instructions below to download and install Postman for your specific platform:
-
Windows:
- Download Postman for Windows from here.
- Run the installer and follow the installation instructions.
-
Mac:
- Download Postman for Mac from here.
- Open the downloaded .dmg file and drag Postman to your Applications folder.
-
Linux (Debian-based distro):
- Download Postman for Linux from here.
- Open a terminal and navigate to the directory where the downloaded file is located.
- Run the following commands:
sudo tar -xzf Postman-linux-x64-8.0.9.tar.gz -C /opt sudo ln -s /opt/Postman/Postman /usr/bin/postman
Lab Activities
Activity 1: Perform a GET Request
- Open Postman.
- In the request URL field, enter the endpoint URL:
http://example.com/devices
. - Select the HTTP method as GET.
- Click the Send button to execute the request.
- Review the response body to see the list of devices returned by the API.
Activity 2: Perform a GET Request for Device Details
- Open Postman.
- In the request URL field, enter the endpoint URL:
http://example.com/devices/{id}
(replace{id}
with the ID of the device you want to retrieve details for). - Select the HTTP method as GET.
- Click the Send button to execute the request.
- Review the response body to see the details of the device.
Activity 3: Perform a DELETE Request (with Authentication)
- Open Postman.
- In the request URL field, enter the endpoint URL:
http://example.com/devices/{id}
(replace{id}
with the ID of the device you want to delete). - Select the HTTP method as DELETE.
- Go to the Authorization tab.
- Select Bearer Token from the Type dropdown.
- Enter the static token
0InfNl5WZuR++sOUD4otAw==
. - Click the Send button to execute the request.
- Verify that the device has been successfully deleted.
Activity 4: Perform a POST Request to Create a New Device (with Authentication)
- Open Postman.
- In the request URL field, enter the endpoint URL:
http://example.com/devices
. - Select the HTTP method as POST.
- Go to the Authorization tab.
- Select Bearer Token from the Type dropdown.
- Enter the static token
0InfNl5WZuR++sOUD4otAw==
. - Go to the Body tab.
- Select Raw and choose JSON from the dropdown.
- Enter the JSON object representing the new device:
{
"serial": "CAT-2960-5483221",
"model": "Catalyst-2960x-48p",
"type": "SWL2",
"interfaces": [
{
"name": "VLAN1",
"address": "192.168.1.100",
"netmask": "255.255.255.0",
"description": "A VLAN",
"status": "Administrative down"
}
]
}
Activity 5: Perform a PUT Request to Update a Device
- Open Postman.
- In the request URL field, enter the endpoint URL:
http://example.com/devices/{id}
(replace{id}
with the ID of the device you want to update). - Select the HTTP method as PUT.
- Go to the Authorization tab.
- Select Bearer Token from the Type dropdown.
- Enter the static token
0InfNl5WZuR++sOUD4otAw==
. - Go to the Body tab.
- Select Raw and choose JSON from the dropdown.
- Enter the updated JSON object representing the device:
{
"serial": "UPDATED_SERIAL_NUMBER",
"model": "UPDATED_MODEL",
"type": "UPDATED_TYPE",
"interfaces": [
{
"name": "VLAN1",
"address": "UPDATED_IP_ADDRESS",
"netmask": "UPDATED_NETMASK",
"description": "UPDATED_DESCRIPTION",
"status": "UPDATED_STATUS"
}
]
}
Conclusion
Congratulations! You have completed the REST API lab using Postman. You have learned how to perform GET, PUT, DELETE, and POST requests, as well as how to handle authentication using Bearer tokens.
If you have any questions or need assistance, feel free to ask your instructor or classmates.
Happy API testing!