Add GET /item/:id endpoint
This new endpoint was so easy to add, it would have been a shame not to do it. Besides, it makes sense since the reponse from `POST /items` provided a `Location` header for the newly created item.
This commit is contained in:
@@ -64,6 +64,14 @@
|
|||||||
{:status 200
|
{:status 200
|
||||||
:body "Ahoy mate, the ship be sailin' alright"})
|
:body "Ahoy mate, the ship be sailin' alright"})
|
||||||
|
|
||||||
|
(defn get-item-handler
|
||||||
|
[request]
|
||||||
|
(let [id (get-in request [:path-params :id])
|
||||||
|
item (db-get-item id)]
|
||||||
|
(cond
|
||||||
|
(nil? item) {:status 404 :body {:error "Not Found"}}
|
||||||
|
:else {:status 200 :body item})))
|
||||||
|
|
||||||
(defn get-items-handler
|
(defn get-items-handler
|
||||||
[_]
|
[_]
|
||||||
{:status 200
|
{:status 200
|
||||||
@@ -101,6 +109,7 @@
|
|||||||
(ring/ring-handler
|
(ring/ring-handler
|
||||||
(ring/router
|
(ring/router
|
||||||
[["/ahoy" {:get ahoy-handler}]
|
[["/ahoy" {:get ahoy-handler}]
|
||||||
|
["/item/:id" {:get get-item-handler}]
|
||||||
["/items" {:get get-items-handler
|
["/items" {:get get-items-handler
|
||||||
:post {:handler create-item-handler
|
:post {:handler create-item-handler
|
||||||
:parameters {:body Item}}}]]
|
:parameters {:body Item}}}]]
|
||||||
|
|||||||
Reference in New Issue
Block a user