ring - Clojure, Compojure-api: Access Request headers -


i trying implement request end point authentication. want access accesstoken value request headers.

my request end point is

curl command

curl -x \   'http://localhost:3000/hello?id=10' \   -h 'accesskey: 23423sfsdfsdfsfg' \   -h 'cache-control: no-cache' \   -h 'content-type: application/json' \   -h 'postman-token: f69b34e6-4888-ec31-5fbc-b734e176571b' \   -d '{     "artwork": {id" : 1} }' 

http command

get /hello?id=10 http/1.1 host: localhost:3000 content-type: application/json accesskey: 23423sfsdfsdfsfg cache-control: no-cache postman-token: b974719d-5e1d-4d68-e910-e9ca50562b2f 

my code method implementation

(defapi app   (get ["/hello/:id", :id #"[0-9]+" ] [id]     (log/info "function begins here")     (def artworkdata (logic/artwork-id (->> id (re-find #"\d+") long/parselong)))     (def data (if (not-empty artworkdata)                {:data artworkdata :status 200}                {:data [] :status 201}))    (ok data))) 

i want fetch accesskey: 23423sfsdfsdfsfg request header.

is there way value , use in method?

i using postman test api end points.

compojure has custom destructuring syntax (i.e., different clojure proper) parameters. can bind whole request map using keyword :as

(defapi app   (get ["/hello/:id", :id #"[0-9]+" ] [id :as request] 

if want request headers, following should work

(defapi app   (get ["/hello/:id", :id #"[0-9]+" ] [id :as {:headers headers}] 

note still allows bind path parameter id.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -