LuminusでJSON APIを作る
ClojureのWebアプリケーションフレームワークLuminusでJSON APIを作る際にRoutingで少し躓いたので手順をメモ
src/APP_NAME/routes/home.clj
これだけではダメ
(defn ping-json [] ; <- 追加 (json {:response "PONG!!!"})) ; <- 追加 (defroutes home-routes ... (GET "/ping" [] (ping-json))) ; <- 追加
namespaceにnoire.responseを追加すると/pingにアクセスしたときJSONが返却されるようになる
(ns APP_NAME.routes.home (:require [compojure.core :refer :all] ... [noir.response :as response])) ; <- 追加 ... (defn ping-json [] ; <- 追加 (response/json {:response "PONG!!!"})) ; <- 追加 (defroutes home-routes (GET "/" [] (home-page)) (GET "/about" [] (about-page)) (GET "/ping" [] (ping-json))) ; <- 追加