HTTP Headers

Photo by Safar Safarov on Unsplash

Background

GET /photos/cat.png HTTP/1.1
Content-Type: image/png
HTTP/1.1 200 OK
Content-Type: image/png
...

What are headers?

How should I use headers?

Common headers

Request headers

Accept: Acceptable media type(s) in the response body
EXAMPLE: Accept: text/html
Authorization: The authorization scheme and any associated tokens for authorizing a user agent
EXAMPLE: Authorization: Basic abcd1234
Content-Type: The media type of the request body
EXAMPLE: Content-Type: application/json
Cookie: Contains cookies previously sent from the server or set in JavaScript via Document.cookie
EXAMPLE: Cookie: sessionToken=abcd1234; HttpOnly

Response headers

Cache-Control: Indicates the cacheing mechanism that should be followed by the client
EXAMPLE: Cache-Control: max-age=86400
Content-Type: The media type of the response body
EXAMPLE: Content-Type: text/html
Set-Cookie: Sends a cookie to the client
EXAMPLE:
Set-Cookie: sessionToken=abcd1234

Further reading

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Converting an app to React Native — How to get started

OOP in JavaScript: Prototypal Inheritance

How to disable swap space for linux

Deep Dive into AppRun Events

Vue 3.0 — continuing the “Art of the Steal”

React Native cookie-based authentication

JaduJobs and Me

[Action required] Your RSS.app Trial has Expired — Sun Dec 19 2021

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nick Fryar

Nick Fryar

More from Medium

RESTful API

How to Expose your localhost server using Ngrok

Passwordless SMS Authentication 101 | Python Edition

How Houwzer speeds growth and innovation for online real estate by gaining insights into API use