MCPcopy
hub / github.com/go-chi/chi / Routes

Method Routes

_examples/todos-resource/todos.go:12–29  ·  view source on GitHub ↗

Routes creates a REST router for the todos resource

()

Source from the content-addressed store, hash-verified

10
11// Routes creates a REST router for the todos resource
12func (rs todosResource) Routes() chi.Router {
13 r := chi.NewRouter()
14 // r.Use() // some middleware..
15
16 r.Get("/", rs.List) // GET /todos - read a list of todos
17 r.Post("/", rs.Create) // POST /todos - create a new todo and persist it
18 r.Put("/", rs.Delete)
19
20 r.Route("/{id}", func(r chi.Router) {
21 // r.Use(rs.TodoCtx) // lets have a todos map, and lets actually load/manipulate
22 r.Get("/", rs.Get) // GET /todos/{id} - read a single todo by :id
23 r.Put("/", rs.Update) // PUT /todos/{id} - update a single todo by :id
24 r.Delete("/", rs.Delete) // DELETE /todos/{id} - delete a single todo by :id
25 r.Get("/sync", rs.Sync)
26 })
27
28 return r
29}
30
31func (rs todosResource) List(w http.ResponseWriter, r *http.Request) {
32 w.Write([]byte("todos list of stuff.."))

Callers

nothing calls this directly

Calls 5

GetMethod · 0.95
PostMethod · 0.95
PutMethod · 0.95
RouteMethod · 0.95
DeleteMethod · 0.95

Tested by

no test coverage detected