【问题标题】:Simple API to write a file in Clojure Luminus在 Clojure Luminus 中编写文件的简单 API
【发布时间】:2014-05-01 04:37:44
【问题描述】:

作为学习 Luminus 的开始,我正在尝试创建一个简单的 API 来与本地服务器环境进行交互。编写一个基本文件似乎是一个很好的开始方式,但我无法让它工作。从home.clj查看我的代码:

(defroutes test-routes
  (GET "/spit/:file-name/:file-text" [file-name file-text] 
    (spit file-name file-text) 
    {:status 200
    :headers {"Content-Type" "text/html; charset=utf-8"}
    :body (str "File name: " file-name "<br />File text: " file-text)}))

Luminus 只返回两个字 Not Found

第二个也不行的例子:

(defroutes test-routes
  (GET "/spit" [] 
     (spit "test.txt" "test")
     {:status 200
      :headers {"Content-Type" "text/html; charset=utf-8"}
      :body (str "File name: "  "<br />File text: " )}))

【问题讨论】:

    标签: rest clojure asp.net-web-api luminus


    【解决方案1】:

    我刚刚想通了。问题是test-routes 未正确添加到handler.clj。所以我从home.clj 中引用了符号test-routes,并将test-routes 添加到app-handler 调用中的路由符号向量中。

    我还发现有时需要重新启动环服务器才能使更改显示在应用程序中。路线似乎也必须在app-routes 之前列出。

    【讨论】:

      猜你喜欢
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      相关资源
      最近更新 更多