compojure

Using LevelDB in a ring/compojure webapp

梦想与她 提交于 2020-01-16 18:06:52
问题 I am am trying to setup LevelDB in a ring/compojure app, and looking for an idiomatic way to to access the opened db descriptor into each request. For example: (defn -main "I don't do a whole lot ... yet." [& args] (println "Opening LevelDB file in db/main") (with-open [main-db (db/open "db/main")] (println "Running server on port 3000") (run-jetty #'web/app {:port 3000}))) How do you access the main-db descriptor into the request handlers? ie.: (defroutes handler (GET "/test" [] (db/put main

Serving data with Ring and Compojure

不打扰是莪最后的温柔 提交于 2020-01-15 11:55:27
问题 I am configuring and setting up a web application to serve the JSON data http://www.ericrochester.com/clj-data-analysis/data/census-race.json file statically. My dependencies: :dependencies [[org.clojure/clojure "1.5.1"] [org.clojure/clojurescript "0.0-2197"] [ring/ring-core "1.1.7"] [ring/ring-jetty-adapter "1.1.7"] [compojure "1.1.3"] [hiccup "1.0.2"] [lein-cljsbuild "0.2.10"]] As the title says I'm using Ring as a development plugin, i.e. :plugins [[lein-ring "0.8.3"]] The Leiningen

Howto use lib-noir stateful-sessions in Compojure

蓝咒 提交于 2020-01-14 09:31:28
问题 I think I have a fairly straightforward problem here. But I've been looking at this screen too long. So I'm trying (and failing) to get stateful sessions working in Compojure. The refheap code paste is here . You can see me trying to use lib-noir (line 62) to initialize stateful sessions. Then when the app is running, I try to make a call to session/put! some data in the session (line 43). Now, this stacktrace says that in session.put!, lib-noir is trying to swap out a session var that hasn't

How to convert map to URL query string in Clojure/Compojure/Ring?

醉酒当歌 提交于 2020-01-14 07:23:41
问题 In Clojure / Compojure, how do I convert a map to a URL query string? {:foo 1 :bar 2 :baz 3} to foo=1&bar=2&baz=3 Is there any utility method to do this in compojure? 回答1: Yes, there is a utility for this already that doesn't involve Hiccup or rolling your own string/join/URLEncoder function: user=> (ring.util.codec/form-encode {:foo 1 :bar 2 :baz 3}) "foo=1&bar=2&baz=3" user=> Compojure depends on ring/ring-core, which includes ring.util.codec, so you already have it. 回答2: Something like:

How to convert map to URL query string in Clojure/Compojure/Ring?

风流意气都作罢 提交于 2020-01-14 07:23:09
问题 In Clojure / Compojure, how do I convert a map to a URL query string? {:foo 1 :bar 2 :baz 3} to foo=1&bar=2&baz=3 Is there any utility method to do this in compojure? 回答1: Yes, there is a utility for this already that doesn't involve Hiccup or rolling your own string/join/URLEncoder function: user=> (ring.util.codec/form-encode {:foo 1 :bar 2 :baz 3}) "foo=1&bar=2&baz=3" user=> Compojure depends on ring/ring-core, which includes ring.util.codec, so you already have it. 回答2: Something like:

Passing state as parameter to a ring handler?

余生颓废 提交于 2019-12-30 04:01:07
问题 How does one inject state into ring handlers most conveniently (without using global vars)? Here is an example: (defroutes main-routes (GET "/api/fu" [] (rest-of-the-app the-state))) (def app (-> (handler/api main-routes))) I would like to get the-state into the compojure handler for main-routes . The state might be something like a map created with: (defn create-app-state [] {:db (connect-to-db) :log (create-log)}) In a non ring application I would create the state in a main function and

How to get Clojure Compojure app to run headless via compiled jar within Docker container?

淺唱寂寞╮ 提交于 2019-12-25 03:21:49
问题 Update : this question has changed since the original set of commenters left responses. Apologies for any confusion. This is my code repository https://github.com/Integralist/spurious-clojure-example you can use it as an example for what I'm working with. Note that the above repo relies on a library I've not yet published to Clojars (as I'm still testing it - hence this question opened). You can see the source code of the library here: https://github.com/Integralist/spurious-clojure-aws-sdk

Compojure app not playing well with with-redefs

丶灬走出姿态 提交于 2019-12-24 00:28:45
问题 I'm writing a Compojure application and am using clj-webdriver to graphically test it. I'm trying to use with-redefs to mock out the function that pulls out data from persistence to just return canned values, but it's ignoring my function overwrite. I know with-redefs works in terms of vars, but it's still not working: project.clj relevant pieces: (defproject run-hub "0.1.0-SNAPSHOT" :main run-hub.handler/start-server) handler.clj: (ns run-hub.handler (:require [compojure.core :refer :all]

How to set the status code in Compojure?

拜拜、爱过 提交于 2019-12-23 21:53:18
问题 I am writing a small website in Clojure and Compojure. I would like to set the HTTP response status for each request based on the data found or not found. The last call is the html5 macro that returns to the handler the html that needs to be sent back to the browser. Is it possible to set the HTTP response status somehow here? (ns myapp.views.layout (:require [hiccup.page :refer (html5 include-css include-js)])) (defn layout [title & content] (html5 (head title) (body content))) 回答1: If you

Compojure Routes losing params info

这一生的挚爱 提交于 2019-12-23 15:29:05
问题 My code: (defn json-response [data & [status]] {:status (or status 200) :headers {"Content-Type" "application/json"} :body (json/generate-string data)}) (defroutes checkin-app-handler (GET "/:code" [code & more] (json-response {"code" code "params" more}))) When I load the file to the repl and run this command, the params seems to be blank: $ (checkin-app-handler {:server-port 8080 :server-name "127.0.0.1" :remote-addr "127.0.0.1" :uri "/123" :query-string "foo=1&bar=2" :scheme :http :headers