import "pkg:/source/services/SearchHistory.bs" namespace Http class SearchHistoryRouter extends HttpRouter function new() super() m.Get("/api/search-history", function(context as object) as boolean response = context.response response.Json(SearchHistory.GetAllSaved()) return true end function) m.Put("/api/search-history", function(context as object) as boolean request = context.request response = context.response payload = request.Json() if payload = invalid response.Default(400, `Invalid JSON payload`) return true end if query = payload.query if query = invalid response.Default(400, `missing "query" property in JSON payload`) return true end if SearchHistory.Save(query) response.Json(SearchHistory.GetAllSaved()) return true end function) m.Delete("/api/search-history", function(context as object) as boolean response = context.response SearchHistory.Clear() response.Default(204, "OK") return true end function) end function end class end namespace