This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-08
Channels
- # adventofcode (49)
- # announcements (2)
- # architecture (4)
- # babashka (48)
- # babashka-sci-dev (4)
- # beginners (7)
- # biff (1)
- # calva (14)
- # cider (6)
- # clj-kondo (1)
- # clj-yaml (1)
- # cljsrn (3)
- # clojure (14)
- # clojure-art (12)
- # clojure-europe (62)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (5)
- # clojurescript (18)
- # clr (4)
- # community-development (9)
- # conjure (2)
- # core-async (3)
- # cursive (2)
- # datomic (2)
- # emacs (8)
- # events (3)
- # graalvm (1)
- # helix (6)
- # holy-lambda (3)
- # jobs (1)
- # off-topic (16)
- # polylith (30)
- # practicalli (11)
- # reitit (5)
- # shadow-cljs (14)
- # slack-help (10)
- # xtdb (6)
Is there a way to set the expected request content type for a route? I have a route that looks like this:
["notify/" {:post {:name "notify"
:tags ["api" "aws"]
:summary "receive notifications from AWS"
:parameters {:body [:map
[:Type :string]
[:MessageId :string]
[:TopicArn :string]
[:Message :string]
[:Timestamp :string]
[:SignatureVersion :string]
[:Signature :string]
[:SigningCertUrl :string]
[:UnsubscribeUrl :string]]}
:responses {200 {:body [:map
[:message :string]]}}
:handler ping}}]
ignore the handler. I'm running into issues where I'm getting a 400 Bad Request error for messages sent from AWS, because they're sending a POST request with a body that looks like JSON, but the content type is set to text/plain instead of application/json.Is there some middleware that allows me to coerce the content type header from text/plain to application/json
found this relevant discussion: https://clojurians.slack.com/archives/C7YF1SBT3/p1572084725199500 Looks like I just need to handle it in the handler
there is nothing bulit-in, but you could:
• add something custom into the route-data, e.g. :content-type "application/json"
• a new middleware that reads the route data (via :compile
hook) and based on that, swaps the content-type header. That needs to be mounted before the muuntaja content negotiation middleware to have effect
@U055NJ5CC not sure what you mean for the first part adding content-type. Yeah second part sounds like too much work. I think it'll be easier to just handle it in the handler