liveBook · Manning

HTTP GET

As explained in Build Financial Software with Generative AI (From Scratch)

GET is an HTTP request method used to retrieve a representation of a resource.

HTTP GET retrieves data from an API endpoint. A GET route defines where a client can ask for a resource; the route then returns a representation, commonly JSON. For a file service, GET /files can return a list of available files. section 4.3.1

Start with a small endpoint before connecting real storage. In FastAPI, @router.get("/files/") associates the URL with an asynchronous handler. The handler can initially return fixed data, giving the frontend, QA process, and tests a stable contract to exercise. section 4.3.1

Retrieve a file list

A client calls GET /files and expects HTTP 200 plus a JSON array such as [{"file":"File_1"},{"file":"File_2"}]. A TestClient test calls client.get("/files"), then checks both the status code and returned JSON. section 4.3.1

Validate a GET endpoint at more than one level:

  • Use an automated test to verify that the URL accepts GET and returns the expected status and payload. section 4.3.1
  • Use a behavior scenario to express that calling /files with GET should produce status 200. section 4.3.1
  • Use Postman to send GET http://localhost:8000/files, inspect formatted JSON, and add response tests. section 4.7
  • Avoid tests that depend on array position when order is not guaranteed; search the returned array for the required item instead. section 4.7
Listing 4.3 Our first API route
@router.get("/files/")  #1
async def read_files():  #2
    return [{"file": "File_1"}, {"file": "File_2"}]  #2

This minimal route connects GET /files to an async handler and returns a temporary JSON file list. section 4.3.1

Listing 4.13 Sample Postman test
pm.test("Response should be JSON and have a 200 status code", function () {
    pm.response.to.be.json; #1
    pm.response.to.have.status(200); #2
});

This Postman test checks that a GET response is JSON and has HTTP status 200. section 4.7

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Walks through route definition and response assertions, while using hardcoded data before real file-header information.
Examples
Uses GET /files, a File_1 and File_2 JSON array, TestClient assertions, BDD scenarios, and Postman tests.
What it assumes
Introduces GET through a defined router and client requests without stating prior HTTP knowledge requirements.
What you can do after
Apply it via FastAPI, TestClient, and Postman to retrieve an endpoint response and validate its status and JSON payload.
How it connects
Connects GET requests with API routes, JSON, HTTP status codes, unit testing, behavior-driven development, and Postman.

Also explained in

Compare how 14 books explain HTTP GET →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.