Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
General Development Skills  ›  Capstone Project

HTTP and HTTPS — The Conversation Your API Has

HTTP / HTTPs Protocol 14 minEvery web request is a method and a path sent by a client, answered by a status code and a body, and HTTPS encrypts that conversation with TLS.

HTTP and HTTPS — The Conversation Your API Has

ASP.NET Core spends its entire life doing one thing: reading HTTP requests and writing HTTP responses. When a phone app asks ReadingRoom for a book, it sends a few lines of text and gets a few lines back. If you can read those lines, you can debug almost any web bug.

The rule

Request: method, path, headers, body. Response: status, headers, body.

A request to ReadingRoom looks like this:

POST /books HTTP/1.1
Host: api.readingroom.example
Content-Type: application/json

{ "title": "Dune", "author": "Frank Herbert" }

And the response:

HTTP/1.1 201 Created
Location: /books/7
Content-Type: application/json

{ "id": 7, "title": "Dune", "author": "Frank Herbert" }

Methods state intent: GET reads, POST creates, PUT replaces, PATCH changes part, DELETE removes. Status codes group by first digit:

  • 2xx success — 200 OK, 201 Created, 204 No Content
  • 3xx go elsewhere — 301, 302, 304 Not Modified
  • 4xx the client got it wrong — 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
  • 5xx the server failed — 500 Internal Server Error, 503 Service Unavailable

HTTP itself is plain text anyone on the network can read. HTTPS is HTTP inside a TLS connection: encrypted, and the server proves its identity with a certificate. ASP.NET Core templates call app.UseHttpsRedirection() to send plain-HTTP visitors to HTTPS, and dotnet dev-certs https --trust sets up a local certificate.

The shortcut

For any status code, read only the first digit and ask whose fault? 2 → it worked. 4 → the caller must change the request. 5 → the server must be fixed. Then read the rest for detail.

Debugging a ReadingRoom callStep 1 of 4
  1. Read the method and path

    GET /books/99: the client wants to read book 99.

The trap: returning 200 OK with an error message in the body. Clients, proxies and monitoring all read the status code; tell the truth there.

Drills

Answer fast — trust the rule.

quick drill

Which method should create a new loan?

quick drill

The API returns 503. Whose problem is it?

quick drill

A client sends a book with no title. Which status fits best?

quick drill

What does HTTPS add on top of HTTP?

quick drill

Which response fits a successful DELETE /books/7 that sends nothing back?

Remember

  • Request: method, path, headers, body. Response: status, headers, body.
  • First digit first: 2 worked, 4 caller's fault, 5 server's fault.
  • HTTPS is HTTP inside TLS; never report errors with a 200.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRead a request and its reply

A client sends POST /books with a JSON body to ReadingRoom and gets 201 Created back. Explain what each part of the request and response means, what status the API should send if the title is missing, and why production must use HTTPS.