Skip to content

Practice Exercise: Basic Computer Networking API Testing with Linux Curl

Introduction

Welcome to the Basic Computer Networking lab designed to equip future Site Reliability Engineers (SREs) with the essential skills of testing APIs using the Linux Curl command. In this lab, you will learn how to make API requests, handle responses, and troubleshoot common issues using Curl. API testing is a fundamental skill for ensuring the reliability and functionality of web services.

Prerequisites

  • A Linux server with Curl installed.
  • Basic familiarity with the Linux command line.

Scenario

As a future SRE, you will often need to test and interact with various APIs to monitor and maintain the health of your services. You will use a Linux server as your client and the publicly accessible API server at https://httpbin.org for practice.


Tasks

Task 1: Making a GET Request

  1. Open a terminal on your Linux server.
  2. Use the "curl" command to make a GET request to the API endpoint: https://httpbin.org/get.
  3. Observe and note the response, including the status code, headers, and content.

curl https://httpbin.org/get

Task 2: Making a GET Request to Another Endpoint

  1. Make a GET request to https://httpbin.org/anything. httpbin.org/anything will look at the request you made, parse it, and echo back to you what you requested. Curl's default is to make a GET request.
  2. Observe and note the response.

curl https://httpbin.org/anything

Task 3: Making a POST Request

  1. Use Curl to make a POST request to https://httpbin.org/anything.
  2. Capture and inspect the response.

curl -X POST https://httpbin.org/anything

Task 4: Making a GET Request with Query Parameters

  1. Make a GET request to https://httpbin.org/anything, but this time add some query parameters (set value=panda).
  2. Analyze the response for the updated query parameters.

curl "https://httpbin.org/anything?value=panda"

Task 5: Requesting a robots.txt File

  1. Request Google's robots.txt file at www.google.com/robots.txt.
  2. Capture and inspect the response.

curl www.google.com/robots.txt

Task 6: Setting a Custom User-Agent Header

  1. Make a GET request to https://httpbin.org/anything.
  2. Set the header User-Agent: elephant.
  3. Capture and inspect the response.

curl -H "User-Agent: elephant" https://httpbin.org/anything

Task 7: Making a DELETE Request

  1. Use Curl to make a DELETE request to https://httpbin.org/anything.
  2. Capture and inspect the response.

curl -X DELETE https://httpbin.org/anything

Task 8: Requesting Headers

  1. Make a GET request to https://httpbin.org/anything and also get the response headers.
  2. Capture and inspect the headers in the response.

curl -I https://httpbin.org/anything

Task 9: Making a POST Request with JSON Body

  1. Make a POST request to https://httpbin.org/anything with the JSON body {"value": "panda"}.
  2. Capture and inspect the response.

curl -X POST -d '{"value": "panda"}' https://httpbin.org/anything

Task 10: Setting Content-Type Header for POST Request

  1. Make the same POST request as the previous exercise, but set the Content-Type header to application/json (because POST requests need to have a content type that matches their body).
  2. Look at the json field in the response to see the difference from the previous one.

curl -X POST -H "Content-Type: application/json" -d '{"value": "panda"}' https://httpbin.org/anything


Sample Troubleshooting Command

Simulate a network issue by disconnecting your internet temporarily. Use curl to make a request during the downtime. Troubleshoot the error message received and suggest potential solutions.