Routes creates a REST router for the todos resource
()
| 10 | |
| 11 | // Routes creates a REST router for the todos resource |
| 12 | func (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 | |
| 31 | func (rs todosResource) List(w http.ResponseWriter, r *http.Request) { |
| 32 | w.Write([]byte("todos list of stuff..")) |