Fork me on GitHub
#ring-swagger
<
2017-01-16
>
borkdude13:01:54

How do I get a compojure-api endpoint to return transit+json, any examples?

ikitommi13:01:43

@borkdude the clients can negotiate the response, done in api: just return clojure data from an endpoint, and if the client send accept-header with value application/transit+json, it’s returned

ikitommi13:01:57

with 1.2 you have more options: create transit body yoirself and set the content-type or add a key :muuntaja.core/content-type with value application/transit+json to the response map => will be forced to be transit.

ikitommi13:01:02

if you have a POST endpoint with defined response model, you can poke with swagger-ui: there is a dropdown to select both the request-format and the response-format.

borkdude14:01:04

I’m dealing with a POST endpoint but I don’t see the response dropdown in swagger. We’re using 1.1.9

borkdude14:01:37

I’m sending accept header transit+json, but it returns json.

borkdude14:01:31

It didn’t work after all, alas. I made a test endpoint which just returns a hash-map. Code:

(POST "/test" []
                  (ok {:foo “bar”}))
Swagger: https://www.dropbox.com/s/z9h8beagk9q4l9k/Screenshot%202017-01-16%2015.18.43.png?dl=0

borkdude14:01:43

I seem to be missing the option to return a different format

ikitommi14:01:04

that's a bug in the swagger-ui. You have to define a response schema for it to work. So, adding :return s/Any should work

ikitommi14:01:56

or :responses {200 {:schema s/Any}} (the long format for same)