Fork me on GitHub

@malcolmsparks: you'll be happy to know I went with the vendor tag 🙂


@malcolmsparks: hate to ask malcolm but by any chance are you working on an JWT access-control example for the docs?


Hi . There are some examples in the repo under dev/ What are you trying to do? Did you see the security chapter with session security?


yea I had a look and combined what I seen in there with the sse example ending up with something like this

:access-control {:authentication-schemes [{:scheme :jwt
                                                             :yada.jwt/secret secret}]}
                  :methods        {:get {:produces "text/event-stream”


though haven’t tested it yet


formatting for that is off it seems on my end


(defn connect []
  (yada/resource {:id             :server.core/connect
                  :summary        "connect to the server"
                  :description    "allows a user to connect to the server to begin to recieve push notifications"
                  ;; TODO check for a valid token
                  :access-control {:authentication-schemes [{:scheme :jwt
                                                             :yada.jwt/secret secret}]}
                  :methods        {:get {:produces "text/event-stream"
                                         :response "return new messages, would better if I could use clojurescript"}}}))


Hi! I'm new to yada and trying to write a small service that can accept arbitrary (potentially binary) data via POST, e.g. to store it on disk or in a database.


Since I want to allow any mime-type for incoming data, I tried to define a yada/resource map with a :consumes #{"*/*"} entry.


But I get a 415 Unsupported Media Type response when I try to send any data (with curl).


What is the best way to define a handler to accept any data?


@cberg: The best approach, I assume from writing out the complete resource model, is that if you want to except all types it is best to not include the :consumes #{} leaving room for a more agnostic approach in which it decides the mime-type on the fly based in the data being consumed


I run into the same problem without defining :consumes. This is my handler:


            {:methods {:post (fn [ctx] (pr-str ctx))}})


$ curl -i  -X POST -d "foo" -H "Content-Type: text/plain"
HTTP/1.1 415 Unsupported Media Type
Content-Length: 644
Content-Type: application/json
Server: Aleph/0.4.1
Connection: Keep-Alive
Date: Tue, 09 Aug 2016 23:34:27 GMT

{"status":415,"message":"Unsupported Media Type","id":"7132f90f-777a-488f-8d86-ff8b661d5571","error":{"error":"clojure.lang.ExceptionInfo: Unsupported Media Type {:status 415, :message \"Method does not declare that it consumes this content-type\", :consumes #{}, :content-type <#C0702A7SB>.media_type.MediaTypeMap{:name \"text/plain\", :type \"text\", :subtype \"plain\", :parameters {}, :quality 1.0}}","data":"{:status 415, :message \"Method does not declare that it consumes this content-type\", :consumes #{}, :content-type <#C0702A7SB>.media_type.MediaTypeMap{:name \"text/plain\", :type \"text\", :subtype \"plain\", :parameters {}, :quality 1.0}}”}}


let me consult the resource model for a second I believe I have noted this case down


hmm it should work, though I am just curious are you intentionally returning the entire ctx for testing/practice purposes? I’d recommend (:body ctx). what kind of content are you trying to consume? you defined the content as text/plain but it found application/json


@cberg: figured out what you are looking for :consumes “*” same as :consumes #{“*”} with the first being preferred for a single type. Though it is usually best to decide up front the mime-types you want to consume, see for a list of them