Fork me on GitHub
#yada
<
2016-08-09
>
bhagany02:08:27

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

severed-infinity20:08:19

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

malcolmsparks20:08:55

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?

severed-infinity20:08:38

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”

severed-infinity20:08:57

though haven’t tested it yet

severed-infinity20:08:41

formatting for that is off it seems on my end

severed-infinity20:08:04

(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"}}}))

cberg22:08:33

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.

cberg22:08:27

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

cberg22:08:23

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

cberg22:08:21

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

severed-infinity23:08:51

@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

cberg23:08:06

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

cberg23:08:18

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

cberg23:08:06

$ 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}}”}}

severed-infinity23:08:52

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

severed-infinity23:08:46

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

severed-infinity23:08:10

@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 http://www.iana.org/assignments/media-types/media-types.xhtml for a list of them