Guides › curl and Headers: Seeing the Whole HTTP Conversation

Lesson 4 of 8 2 min read All lessons

curl and Headers: Seeing the Whole HTTP Conversation

Every time you request a webpage or call an API, the client and server exchange an unseen conversation before transmitting the actual data. This conversation happens inside HTTP headers.

Imagine mailing a package across the country. The physical gift inside the box is the body (your JSON data). But the shipping label, priority sticker, customs declarations, and fragile instructions taped to the exterior are the headers. They instruct mail couriers and recipients how to inspect, route, and handle the package before opening it.

The three headers you need to know

Inspect headers three ways

1. In your browser

Open Developer Tools in your browser (press F12 or right-click and choose Inspect), switch to the Network tab, and reload https://api.computewithpour.com/v1/get/name. Click the request to view both request and response headers.

2. With curl

In your terminal, add the -i flag to curl. This forces curl to show the HTTP status line and all headers before printing the JSON body:

curl -i https://api.computewithpour.com/v1/get/name

3. With Python

The requests library exposes response headers through the r.headers case-insensitive dictionary:

import requests

r = requests.get("https://api.computewithpour.com/v1/get/name")
print("Content-Type:", r.headers.get("Content-Type"))
print("Cross-Origin Policy:", r.headers.get("cross-origin-resource-policy"))

Try it in the API Lab

Visit the API Lab and look at the request echo. Notice how each button press triggers a clean GET request and reports the server response headers and round-trip timing.

What to notice

Notice that our practice API serves application/json; charset=utf-8. Notice also that if you attempt to push data using an unsupported HTTP verb—for example by running curl -i -X POST https://api.computewithpour.com/v1/names—the server halts you with 405 Method Not Allowed and sends an Allow: GET, HEAD, OPTIONS header explaining what methods are permitted.

Precision with Python building blocks

Reading network headers, managing status codes, and parsing dictionaries with keys and values requires confidence with Python's foundational grammar and data structures. When you want a crystal-clear reference for every core syntax tool in Python, open 35 PY Keys in our library.

Challenge

Use Python to inspect the response headers of /v1/tips. Print the Content-Type, check if caching is enabled via Cache-Control, and confirm that sending a POST request to /v1/names returns status 405.

Show the answer

Headers act like a dictionary in Python via r.headers. You will find application/json for content type and public caching. Sending an unauthorized method like POST to our read-only API returns 405 Method Not Allowed.

import requests

base = "https://api.computewithpour.com"
r = requests.get(f"{base}/v1/tips")
print("Content-Type:", r.headers.get("content-type"))
print("Cache-Control:", r.headers.get("cache-control"))

bad_post = requests.post(f"{base}/v1/names")
print("POST status code:", bad_post.status_code)  # 405