CARVIEW |
Select Language
HTTP/2 200
date: Fri, 25 Jul 2025 07:19:45 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"4cadad96333dce60e825f1ae9d27f5ea"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=0lEGioih0QnKZCrTQXFluJ1m1%2BUEGQNeK8KpnKYpyu7IKnwCwaO57facrWfYG%2B5nakSyOr%2BcNC4%2F7IcuS5cIK0ziKG1lBy1VQXbQm2gFNcmCaAtVbS0Q7noClTOP%2BLr9u3Yp2%2B9OKc22T3WB292u7e%2F5uc5nH3LscfAA3Wj9b53F9%2F8QyKS3jMWPSEB95J%2FPYlvcoVvvNkK9HqGIb1B897PFCo4GyQFCzJSMGMEf9EXvOZSr49zBmigo%2FyorfMgY%2BgDw7uRMq8FgETGUegeMWg%3D%3D--pI%2B%2BSVmxsHYNv8LU--hXqOVIxx6L%2FHpz4R3%2Br5pQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.739053.1753427985; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 07:19:45 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 07:19:45 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: DAF0:2C1B9F:447FEE:53EABA:68833011
Creating your own metadata handlers · metosin/compojure-api Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 149
Creating your own metadata handlers
Tommi Reiman edited this page Feb 9, 2016
·
2 revisions
Compojure-api handles the route metadata by calling the multimethod compojure.api.meta/restructure-param
with
metadata key as a dispatch value.
Multimethods take three parameters:
- metadata key
- metadata value
- accumulator map with keys
-
:lets
, a vector of let bindings applied first before the actual body -
:letks
, a vector of letk bindings applied second before the actual body -
:middleware
, a vector of route specific middleware (applied from left to right) -
:swagger
, swaggerd-data of a route (without the key & value for the current multimethod) -
:body
, a sequence of the actual route body
-
.. and should return the modified accumulator. Multimethod calls are reduced to produce the final accumulator for
code generation. Defined key-value -based metadatas for routes are guaranteed to run on top-to-bottom order of the so
all the potential let
and letk
variable overrides can be solved by the client. Default implementation is to keep
the key & value as a route metadata.
Creating your own meta-data handler for role-based security.
(defn require-role! [required roles]
(if-not (seq (clojure.set/intersection required roles))
(ring.util.http-response/unauthorized! {:text "missing role", :required required, :roles roles})))
(defmethod compojure.api.meta/restructure-param :roles [_ roles acc]
(update-in acc [:lets] into ['_ `(require-role! ~roles (:roles ~'+compojure-api-request+))]))
Using it:
(GET "/admin" []
:roles #{:admin}
(ok {:message "welcome!"})))
(r {:request-method :get :uri "/admin"})
; => throws 401
(r {:request-method :get :uri "/admin" :roles #{:admin}})
; => ok
macroexpanding-1 it too see what's get generated:
; normal case
(macroexpand-1
`(GET "/admin" []
(ok {:message "welcome!"})))
; (compojure.api.routes/create
; "/admin"
; :get
; (compojure.api.meta/merge-parameters {})
; nil
; (compojure.core/make-route
; :get
; #clout.core.CompiledRoute{:source "/admin", :re #"/admin", :keys [], :absolute? false}
; (clojure.core/fn [request__14718__auto__]
; (compojure.core/let-request [[:as +compojure-api-request+] request__14718__auto__]
; (do (ring.util.http-response/ok {:message "welcome!"}))))))
(macroexpand-1
`(GET "/admin" []
:roles #{:admin}
(ok {:message "welcome!"})))
; (compojure.api.routes/create
; "/admin"
; :get
; (compojure.api.meta/merge-parameters {})
; nil
; (compojure.core/make-route
; :get
; #clout.core.CompiledRoute{:source "/admin", :re #"/admin", :keys [], :absolute? false}
; (clojure.core/fn [request__14718__auto__]
; (compojure.core/let-request [[:as +compojure-api-request+] request__14718__auto__]
; (clojure.core/let [_ (sampo.restructure/require-role! #{:admin} (:roles +compojure-api-request+))]
; (do (ring.util.http-response/ok {:message "welcome!"})))))))
You can’t perform that action at this time.