HTTP and REST in Plain Words
Learn the conversation every API has: a request with a method, an address, headers and a body, and a response with a status code, headers and a body. You'll read status codes as sentences, design endpoints the REST way, and answer a community garden's requests by hand in plain Python, so you see exactly what a framework takes over.
Updated
HTTP in Plain Words
- HTTP in Plain Words: Requests and Responses (Apprentice): An app that asks an API for something sends an HTTP request with a method, a URL, headers and sometimes a body, and gets back a response with a status code, headers and usually a body, and Python's urllib.parse splits a URL into its path and its query values.
- Status Codes and Headers (Apprentice): A response's three-digit status code tells the app how its request went before it reads a word of the body, its first digit names the family (2xx it worked, 3xx look elsewhere, 4xx the request has a problem, 5xx the server broke), and headers such as Content-Type tell the app how to read the body.
REST in Plain Words
- REST: Resources, Endpoints and Methods (Apprentice): A REST API names each kind of thing it holds with a plural noun, such as /plots for every plot and /plots/7 for one, lets the HTTP method be the verb, answers each action with the status code that fits it, and never changes anything on a GET.
- Routing by Hand, and Why Frameworks Exist (Apprentice): A plain Python function can answer requests by checking each one's method and path with if statements and returning a status code and a body, and seeing that code grow with every route shows the jobs a framework such as FastAPI takes over.
Exercise: Community Garden Requests
- Exercise: Community Garden Requests (Apprentice): Answer Greenleaf Community Garden's requests by hand in plain Python, with a function that reads each request's method, path and query string and returns the right status code and body, a 404, 400 or 405 included, and let pytest check every answer.