Fork me on GitHub
#reitit
<
2019-01-07
>
aaron5101:01:33

What’s the best way to force the request body to be JSON parsed, even if the request’s content type is text/plain, on only one route? So that I can use parameter coercion even if the content-type is text/plain?

aaron5101:01:14

I see this would be in Muuntaja… https://github.com/metosin/muuntaja#http-format-negotiation “These keys can also be set manually, overriding the content negotiation process” - not sure what keys these are, or where to set them, yet

aaron5103:01:28

Ended up with this: (muuntaja/create (assoc muuntaja/default-options :formats {"application/json" json-format/format "text/plain" json-format/format}))

aaron5103:01:49

Would be nice to override Content-Type at all times because these endpoints should always produce & consume JSON. Not sure how to do that with Muuntaja yet

ikitommi14:01:45

@U3JH0P5LJ you can put the :muuntajainstance into that route only. Looks right otherwise.

ikitommi14:01:07

for all request formats, you can override the [:http :extract-content-type] option in that muuntaja instance to always return application/json = "everything looks like json".

aaron5123:01:17

Awesome, thank you

ikitommi16:01:48

@whoneedszzz The overlap is there, as reitit aims to be the routing assembly language of choice, supporting many targets. Kind of like “library for creating routing frameworks, with some samples”. Roadmap-wise, we are now focusing on perf & dev-tools. Node.js support would be great to get on par with the JVM-parts, just for fun, we are not using it ourselves. If you want to try something new & bleeding edge, I would try reitit-http with sieppari. Supports core.async, manifold and promesa out-of-the-box. And the Interceptor compilation is actually really cool feature.