Skip to content

Commit

Permalink
reafctoring REST example
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 26, 2024
1 parent 260a1ed commit 72daff0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions doc/examples/scripts/webapp/rest-webapp.venice
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
(defn create-employee [request]
(let [json? (ring/json-request? request)
body (if json? (json/slurp (:body request) :key-fn keyword) nil)
employee (if body {:name (:name body), :role (:role body)})]
employee (if body {:name (:name body), :role (:role body)} nil)]
(cond
(not json?) { :status 400
:headers { "Content-Type" "text/plain; charset=utf-8" }
Expand All @@ -85,14 +85,14 @@
employee (find-employee-by-id id)
json? (ring/json-request? request)
body (if json? (json/slurp (:body request) :key-fn keyword) nil)
employee* (if body {:id id, :name (:name body), :role (:role body)})]
employee* (if body {:id id, :name (:name body), :role (:role body)} nil)]
(cond
(nil? employee) { :status 404
:headers { "Content-Type" "text/plain; charset=utf-8" }
:body "Employee with the id ~{id} not found!" }
(not json?) { :status 400
:headers { "Content-Type" "text/plain; charset=utf-8" }
:body "Not a json request!" }
(nil? employee) { :status 404
:headers { "Content-Type" "text/plain; charset=utf-8" }
:body "Employee with the id ~{id} not found!" }
:else { :status 200
:headers { "Content-Type" "application/json; charset=utf-8" }
:body (json/write-str (add-employee employee*)) } )))
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/com/github/jlangch/venice/tomcat.venice
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
(send-html res 404 (html-box-page "Not Found (404)" msg)))

(defn send-internal-error [res msg]
(send-html res 500 (html-box-page "Internal Error (501)" msg)))
(send-html res 500 (html-box-page "Internal Error (500)" msg)))

(defn send-not-implemented [res msg]
(send-html res 501 (html-box-page "Not Implemented (501)" msg)))
Expand Down

0 comments on commit 72daff0

Please sign in to comment.