Fork me on GitHub
#yada
<
2017-04-24
>
borkdude08:04:55

I’ve asked it before but I’ll try again: can anyone give an example of this key in the Schema? What is it for exactly? https://github.com/juxt/yada/blob/master/src/yada/schema.clj#L50

dominicm08:04:52

@borkdude I think you can mandate headers like you would query parameters

borkdude08:04:26

@dominicm I think so too. Say I want to mandate a header like “x-my-custom-header”, what should the resource parameter entry look like?

dominicm08:04:32

I'm guessing: {"x-my-custom-header" String}

borkdude08:04:32

This gives me a 500:

(defresource new-echo-resource []
  {:methods
   {:post
    {:parameters {:header {“x-my-custom-header” String}}
     :response (fn [ctx]
                 {:res (-> ctx :parameters)})}}})

dominicm09:04:39

I'm not saying the tests definitely pass 😉. Just that this is the intended usage afaict.

borkdude09:04:05

Yeah, the required-key doesn’t yield the 500, but maybe the header is filtered somewhere else before it arrives at the resource

malcolmsparks09:04:41

In schema, if you want a string key to be required, you must wrap in (s/required-key "x-my...")

malcolmsparks09:04:57

Keywords get special treatment

borkdude09:04:40

Ah ok. Any idea why I still get the {:status 400, :errors ([:header {:error {"X-Foo" missing-required-key}}])} when I provide the header in a REST client?

borkdude09:04:28

I think I found it. I have to provide the header name in lowercase in the Schema, because probably somewhere else in the interceptor chain every header name is lowercased.

borkdude15:04:49

Can I get class-path-resource to not respond on directories? E.g. a request to /js now responds with some text that represents a directory listing of /public/js.

dominicm15:04:25

@borkdude ah, thanks for resolving that itch for me ❤️. That's not brilliant I suppose.

borkdude15:04:45

(yada/response-for
   (-> (yada/as-resource (io/resource (.getPath (java.io.File. "public/js")))))
   :get)
;;=>
{:status 200,
 :body "app.cljs.edn\napp.js\napp.out\n"}