java - 如何使web开发更简单?(clojure web dev)
大家讲道理
大家讲道理 2017-04-17 13:20:55
0
2
263

最近研究了下clojure语言,和该语言的一些web库框架,ring,compujure做了一个简单的框架Road:

(defn render-test [ret tmt]
  (-> (resp/response "------render----test------") 
    (#(resp/content-type %1 "text/plain"))))

(defn foo
  "I don't do a whole lot."
  [x]
  (str "来自源码目录的参数:" x))

(defn handler [^Integer x]
    {:$r render-test :text (str "hello world, road goes sucess!" (foo x))})

(defn home [req content ^Integer num]
    {:hiccup "home.clj" :content (str "home" content) :num num})

(defroad road (GET "/web-test-0.1.0-SNAPSHOT-standalone/main" handler) 
              (GET "/web-test-0.1.0-SNAPSHOT-standalone/home/:num{\\d+}" home))

(defn -main [& args]
  (log/info "---------log4j test-------")
  (jetty/run-jetty road {:port 3000}))

https://github.com/zhujinxian/road

框架可以把URI直接映射为一个函数,函数的参数名字对应http传过来的参数的key对应的值,类型用tag修饰。默认string, 函数返回一个map该map被渲染器渲染后返回给浏览器。

可以直接达成jar包独立运行或放在nginx-clojure里跑,或者打包为war放在tomcat里。

这个框架是否足够简单,足够快速,给些建议和改进措施?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!