From 53a5b271eae38913307793fa9884856709c4f822 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 13 Aug 2026 20:53:24 +0200 Subject: Add JSON-based API under `/api` This commit provides an unstable JSON API for communication with an upcoming Dart frontend. Later it might be part of the public interface for integration into other services. For this step it has to be ensured the semantics are not changing a lot in the future which is currently out of scope. --- server.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'server.go') diff --git a/server.go b/server.go index 3b17227..03c8251 100644 --- a/server.go +++ b/server.go @@ -26,12 +26,21 @@ func NewServer(addr string, db *model.DB) *Server { mux.Handle("GET /version", view.VersionRead(version)) + mux.Handle("GET /api/recipes", view.ReadJSON[*model.Recipes](db, model.NewRecipes)) mux.Handle("GET /recipes", view.RecipesRead(db)) mux.Handle("GET /recipe/create", view.RecipeCreate()) + + mux.Handle("POST /api/recipe", view.CreateJSON[*model.Recipe](db, model.NewRecipe)) mux.Handle("POST /recipe", controller.RecipeCreate(db)) + + mux.Handle("GET /api/recipe/{id}", view.ReadJSON[*model.Recipe](db, model.NewRecipe)) mux.Handle("GET /recipe/{id}", view.RecipeRead(db)) + + mux.Handle("POST /api/recipe/{id}", view.UpdateJSON[*model.Recipe](db, model.NewRecipe)) mux.Handle("POST /recipe/{id}", controller.RecipeUpdate(db)) + + mux.Handle("DELETE /api/recipe/{id}", view.DeleteJSON[*model.Recipe](db, model.NewRecipe)) mux.Handle("DELETE /recipe/{id}", controller.RecipeDelete(db)) mux.Handle("GET /favicon.ico", view.FaviconRead()) -- cgit v1.3.1