AI Workshop: learn to build apps with AI →
HTTP: HTTP Request Headers

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Every HTTP request has a set of mandatory and optional headers.

We have a lot of them, but here I’ll list the most important and useful ones.

Host

Host: flaviocopes.com

The domain name of the server, and the port number on which the server is listening. If the port is omitted, 80 is assumed.

This is the only mandatory HTTP request header

All the other headers are listed in alphabetical order.

Accept

Accept: application/json

The MIME type we want for the response

Accept-Charset

Accept-Charset: utf-8

The charset we want for the response

Accept-Encoding

Accept-Encoding: gzip, deflate

Acceptable encodings for the response

Accept-Language

Accept-Language: en-US

The languages we want for the response

Authorization

Authorization: Basic 34i3j4iom2323==

To pass authentication credentials, for example a token

Cache-Control

We can set the caching rules using this header.

  • Cache-Control: no-cache tells the server to revalidate the data before sending the response to make sure it’s current
  • Cache-Control: max-age=30 tells the server we want data that’s not older than 30 seconds

Content-Length

Content-Length: 348

The length of the request body in bytes

Content-Type

Content-Type: application/x-www-form-urlencoded

The content type of the body of the request (used in POST and PUT requests).

Cookie: name=value

Sends a cookie to the server

Referer

Referer: https://flaviocopes.com

The address of the previous web page from which a link to the currently requested page was followed.

User-Agent

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

The string that identifies the user agent (the browser)

Lessons in this unit:

0: Introduction
1: An HTTP request
2: HTTP Methods
3: HTTP Status Codes
4: HTTP Client/Server communication
5: ▶︎ HTTP Request Headers
6: HTTP Response Headers
7: HTTPS
8: HTTP/2
9: HTTP/3
10: The HTTP/2 protocol
11: Caching in HTTP
12: The curl guide to HTTP requests
13: ▶︎ The HTTP Request Headers List
14: The HTTP Response Headers List
15: HTTP vs HTTPS
16: The HTTPS protocol
17: An introduction to REST APIs
18: What is an RFC?
19: How to generate a local SSL certificate