Add Blog Posts CRUD with SQLite
- Add modernc.org/sqlite (pure Go, no CGO) - Create models package with Post struct - Implement SQLite connection and schema auto-creation - Add CRUD methods to database package - Create post handlers with JSON API - Register API routes: GET/POST/PUT/DELETE /api/v1/posts - Set default DBURL to file:./data.db with WAL mode
This commit is contained in:
@@ -63,6 +63,13 @@ func (s *Server) SetupRoutes() {
|
||||
|
||||
s.router.Route("/api/v1", func(r chi.Router) {
|
||||
r.Get("/now", s.h.HandleNow())
|
||||
|
||||
// Posts CRUD
|
||||
r.Get("/posts", s.h.HandleListPosts())
|
||||
r.Post("/posts", s.h.HandleCreatePost())
|
||||
r.Get("/posts/{id}", s.h.HandleGetPost())
|
||||
r.Put("/posts/{id}", s.h.HandleUpdatePost())
|
||||
r.Delete("/posts/{id}", s.h.HandleDeletePost())
|
||||
})
|
||||
|
||||
// if you want to use a general purpose middleware (http.Handler
|
||||
|
||||
Reference in New Issue
Block a user