HTTP and HTTPS Fundamentals: Requests, Responses, Status Codes, and Headers

Read an HTTP request and response and understand what HTTPS protects

🎯 Introduction

By the end of this article, you will be able to read an HTTP request and response and identify what HTTPS protects.

📤 A request expresses what the client wants to do

The following example represents a query as readable HTTP/1.1 text. HTTP/2 and HTTP/3 use different wire formats, but the method, address, status, and headers retain these meanings:

GET /api/users/1 HTTP/1.1
Host: api.example.com
Accept: application/json

GET is the request method and indicates a read operation; /api/users/1 is the target path. Host specifies the destination host, and Accept indicates that the client wants JSON. An empty line separates the headers from the body. This GET request has no body.

When submitting data, the method and body might look like this:

POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"name":"Ming"}

The request's Content-Type describes the format of the body sent by the client. Here, application/json means that the body is JSON.


📥 A response tells the client the result

A successful creation can return:

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Location: /api/users/1

{"id":1,"name":"Ming"}

201 means a new resource was created, and Location provides its address. The response headers describe the returned content's format; the body contains the actual data. The frontend should check whether the status indicates success before processing the body according to the API contract.


🚦 Status codes describe categories of results

StatusMeaningWhat the caller should do
200Success, usually with a bodyRead the data defined by the API contract
201Resource createdSave the new record's ID or address
204Success with no bodyDo not attempt JSON parsing
400Invalid inputCorrect the parameters and retry
401 / 403No valid identity / insufficient permissionsSign in or display a permission error
404Target not foundCheck the address or resource ID
409Conflict with the current stateHandle a username that is already taken, for example
429Too many requestsWait as directed by Retry-After
500Internal server failureRecord the request ID and investigate the service

An HTTP failure can still be a network response that was successfully received. Browser fetch does not automatically throw solely because it receives a 400 or 500 status. The caller must check the status.


🔒 HTTPS protects transport; business validation remains your responsibility

HTTPS adds TLS protection to HTTP communication. TLS negotiates communication keys and lets the client verify the server through its certificate, reducing the risk of data being read or modified in transit.

The server certificate must match the domain and be trusted by the client. Ignoring a browser warning does not resolve a certificate error. Production login endpoints use HTTPS to keep passwords and session credentials from crossing the network in plaintext.

HTTPS does not automatically stop users from modifying other people's profiles, nor does it fix plaintext password storage in a database. Transport protection, authorization checks, and password storage operate in different places.


🔎 Locate this information in a real request

Select an API request in the browser developer tools' Network panel. Inspect its method, address, status, request headers, response headers, and body. Request Payload is not the server's return value, and Response Headers are not configuration sent by the client.

Developer tools layouts and labels may change between browser versions. Locate the corresponding request, headers, and response sections.

When checking an existing endpoint from a terminal, curl -i displays both response headers and the body. This helps distinguish a server error response from a browser restriction on reading it.


❓ Questions and Answers

Q1: Are request and response headers interchangeable?

No. The server sets Set-Cookie in a response, while the browser sends Cookie in subsequent requests. Their directions and meanings differ.

Q2: Does 200 guarantee business success?

A well-designed API should align the status with the outcome. Returning 200 for business failures can mislead callers and monitoring systems.

Q3: Can HTTPS hide a password in a URL?

Transport is encrypted, but the full URL may still appear in browser history and server logs. Do not put passwords in URLs.


🧪 Practice

Select a JSON endpoint in Network. Record its method, status code, and Content-Type, and determine whether the body comes from the client or the server.

// Write your code or record your verification results here