liveBook · Manning

Chi

As explained in Build and Orchestrator in Go (From Scratch)

chi is a lightweight Go HTTP router for mapping requests to handler functions.

chi is a lightweight Go HTTP router for defining parameterized routes and connecting HTTP requests to handlers. It fills a gap in Go’s standard http package, whose routing support is not robust or convenient for paths such as /tasks/{taskID}. section 5.1 section 1.7

A useful mental model is a layered API: the Go HTTP server listens for requests, chi supplies routes, routing, and handlers, and application code performs the worker’s operations. section 5.1

A worker API can map HTTP methods and paths to task operations:

  • GET /tasks returns a list of tasks. section 5.1
  • POST /tasks creates or starts a task. section 5.1
  • DELETE /tasks/{taskID} stops the task identified by the path parameter. section 5.1
Figure 5.2 Internally, the worker’s API is composed of an HTTP server from the Go standard library; the routes, router, and handlers from the chi package; and, finally, our own worker.
05-02

The architecture figure makes the boundary between Go’s HTTP server, chi’s routing layer, and application handlers explicit. section 5.1

How Build and Orchestrator in Go (From Scratch) covers it

How deep it goes
Explains route parameters and API layering, but stops short of chi’s internal routing implementation.
Examples
Demonstrates GET /tasks, POST /tasks, and DELETE /tasks/{taskID} for worker task operations.
What you can do after
Apply chi to define an HTTP API whose paths and methods dispatch to application handlers.
How it connects
Connects HTTP servers, routes, handlers, REST APIs, and Go’s standard http package.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build and Orchestrator in Go (From Scratch). The section links point to the parts of the book it draws on.