This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-08
Channels
- # announcements (1)
- # babashka (28)
- # beginners (30)
- # calva (1)
- # cider (13)
- # clojure (26)
- # clojure-brasil (2)
- # clojure-europe (29)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (4)
- # clojure-uk (5)
- # cursive (17)
- # data-science (15)
- # datomic (8)
- # emacs (8)
- # events (1)
- # hyperfiddle (54)
- # joyride (18)
- # jvm (2)
- # kaocha (8)
- # lsp (8)
- # malli (4)
- # missionary (11)
- # reagent (5)
- # reitit (13)
- # releases (2)
- # rum (2)
- # scittle (6)
- # shadow-cljs (3)
Is there a cool+up-to-date template around using reitit, sieppari, malli coercion, and then some more?
Yeah I have a few candidates to copy from, but probably I could borrow some extra stuff for extra production-gradeness (?)
I always had a bad time writing templates because of text manipulation. Got anything that can take a project and derive a template from it?
continuing my journey of practicing reitit/building rest-ish APIs; is there a prescribed way for returning reference-URIs for resources?
I might be using the wrong terminology, so let me use a specific example:
suppose I have a resource as part of a personnel management API, in which each employee may have a manager
, which is another employee, so:
given the request "GET https://<root-domain>/api/employees/277" (defined in a reitit.ring/router
), I would like to return information like so
{
"email": "[email protected]",
"name": "john smith",
"manager-id": 16,
"manager": "https:///api/employees/16"
}
suppose my handler for that resource is written as
(fn [request]
{:status 200
:body (employee/get-by-id (-> request :parameters :path :id)))
which returns a map of the name
, email
, and manager-id
what should I assoc
to that map to get the manager
reference I'm hoping for? I could of course 'manually' add the string, but that would break should the
ever change, I figure it might have something to do with passing through the :reitit.core/router
, but I've only been futzing around in the dark with it so far.okay, so I see I can get the path relative to the API root via (-> request :ring.core/router (reitit.core/match-by-name ::employee {:id 16}) :path)
, I guess I can try and derive the active host-name by some other way and prepend it~
could i ask what your go-to method is for reliably getting the domain-name/scheme+authority of the request? (the http(s)://
)
In production, my app is behind an apache reverse-proxy. So I first check if there is a x-forwarded-for
header, and then check the host
header
(defn get-host
[request]
(let [headers (:headers request)]
(get headers "x-forwarded-host" (get headers "host"))))
I think that the scheme is found in (:scheme request)
, note that it contains a keyword, :http
or :https
I suppose this would be more idiomatic
(defn get-host
[request]
(let [headers (:headers request)]
(or (get headers "x-forwarded-host")
(get headers "host"))))