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

Method Routes

_examples/todos-resource/users.go:12–28  ·  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 usersResource) Routes() chi.Router {
13 r := chi.NewRouter()
14 // r.Use() // some middleware..
15
16 r.Get("/", rs.List) // GET /users - read a list of users
17 r.Post("/", rs.Create) // POST /users - create a new user 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 users map, and lets actually load/manipulate
22 r.Get("/", rs.Get) // GET /users/{id} - read a single user by :id
23 r.Put("/", rs.Update) // PUT /users/{id} - update a single user by :id
24 r.Delete("/", rs.Delete) // DELETE /users/{id} - delete a single user by :id
25 })
26
27 return r
28}
29
30func (rs usersResource) List(w http.ResponseWriter, r *http.Request) {
31 w.Write([]byte("users 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