|
From: Stas B. <sta...@gm...> - 2022-06-13 16:27:31
|
See https://edicl.github.io/hunchentoot/#content-type* On Mon, Jun 13, 2022 at 7:12 PM steph.tougard via Sbcl-help <sbc...@li...> wrote: > > Hello all, > > Not sure it's the right place, in case it's not, please just ignore (or point me to the right direction). > > With Hunchentoot, I'm using > > (defmacro http-route (url fun) > `(push (create-prefix-dispatcher ,url ,fun) *dispatch-table*)) > > To fill up the dispatch table. > > (http-route "/groups" #'groups) > (http-route "/edit-group" #'edit-group) > (http-route "/peers" #'peers) > (http-route "/key" #'key) > > The default content type is "text/html", which is fine as long as I'm building an HTML back office. > > But how to add a dispatcher who returns JSON ? > > (http-route "/json" #'json) > > Seems that create-prefix-dispatcher only handle URI => Function. I know there is a default variable to change the content-type, but I don't want a default, I only want a "application/json" content type for this specific URI. > > I get this: > > curl -v http://localhost:3500/json > > * Trying 127.0.0.1:3500... > > * Connected to localhost (127.0.0.1) port 3500 (#0) > > > GET /json HTTP/1.1 > > > Host: localhost:3500 > > > User-Agent: curl/7.79.1 > > > Accept: */* > > > > > * Mark bundle as not supporting multiuse > > < HTTP/1.1 200 OK > > < Content-Length: 17 > > < Date: Mon, 13 Jun 2022 15:56:36 GMT > > < Server: Hunchentoot 1.3.0 > > < Content-Type: text/html; charset=utf-8 > > < > > * Connection #0 to host localhost left intact > > {"Hello":"World"}% > > > > > > Thanks guys for the help. > > Best > > _______________________________________________ > Sbcl-help mailing list > Sbc...@li... > https://lists.sourceforge.net/lists/listinfo/sbcl-help |