Is there a cool+up-to-date template around using reitit, sieppari, malli coercion, and then some more?
I usually just copy the example from the examples directory
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?
That would be cool! But nope
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": "employee277@gmail.com",
"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.That is the way I would do 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"))))ahh perfect! i appreciate it ❤️
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~