Here is comporoute, a ring handler without any macro magic, aimed at composability and extensibility. Even though it's in early alpha state it has precise docstrings already. It has a feature called inner middleware to solve the issue you are having. You may (and should) use it only for what...
clojure,swagger,ring,compojure
There is no definition in the Swagger Spec for the "missed everything else" default handler of Compojure. Swagger is about documenting existing apis, not the non-existing. Just discussed about this at #swagger on freenode. Still, you can describe the default routes manually with compojure-api, created a sample here: https://gist.github.com/ikitommi/cdf19eeaf4918efb051a. Note:...
Here's kind of the default template I use for new projects. It allows you to do dependency injection into ring apps and run the app from the command line as an uberjar. You can read more here: http://www.sparxeng.com/blog/software/improved-clojure-workflow ; handler.clj (defn wrap-inject-deps "Ring middleware that injects the dependencies into each...
Found a solution. Turns out this problem is 'somewhat' related to Compojure/Ring: Why doesn't a session with cookie-store survive a server restart?, which explains that 2 session middleware are being used: One by compojure, one by wrap-session. After changing both middleware to the same storage engine, the atom is filled...
clojure,read-eval-print-loop,ring,compojure
#'app-routes is a reader macro that expands to (var app-routes). When a var is used as if it were a function, it is dereferenced anew on each invocation, and then the value returned by that deref is called. If you were to supply app-routes as the argument, the compiler would...
Not actually at a REPL, but isn't this as straightforward as returning nil from html/display-thing if there's no id element in my-map? Take a look at (source GET) to see how the macro passes control to the next route if the method or URL don't match.
You are correct: (def app (wrap-defaults app-routes site-defaults)) Is equivalent to: (def app (-> app-routes (wrap-defaults api-defaults))) The arrow is called the Thread-First Macro and allows you to write nested s-expressions in a linear way. In your second example, it makes sense that my-middleware2 is called before my-middleware1 when an...
facebook,clojure,leiningen,compojure,ring
I think the basic answer to your question is that functional programming is more about input and output (think of a mathematical function), whereas imperative programming tends to be more about side effects and mutable data. Instead of thinking, "what do I need to do?", think, "what kind of data...
intellij-idea,clojure,ring,compojure
You want to run the server from inside the repl? Add [ring/ring-jetty-adapter "1.3.1"] as a dependency In the REPL: (require 'ring.adapter.jetty) (require 'quals.core.handler) ; require YOUR ns containing the handler (ring.adapter.jetty/run-jetty quals.core.handler/app {:port 3004}) You can see all the parameters you can pass here: http://mmcgrana.github.io/ring/ring.adapter.jetty.html There you have it, the...
clojure,leiningen,compojure,heroku-postgres
Ragtime 0.3.9 uses the scheme from the connection url as the dispatch value for the connection multimethod. The code is here and here. But the DATABASE_ENV from heroku doesn't have a "jdbc" but a "postgres" scheme (which makes sense, it has to be generic). A workaround could be to add...
twitter-bootstrap,clojure,ring,compojure
Bower fulfils my requirements. Prerequisites are installing Bower through NPM and lein-bower Leiningen plugin. Below are the configuration details I had to add to project.clj: :plugins [[lein-bower "0.5.1"]] :bower-dependencies [[bootstrap "3.3.2"]] :bower {:directory "resources/public/lib"} @Aleš Roubíček - thanks for your comment....
clojure,oauth-2.0,ring,compojure,luminus
Based on the documentation for Google's OAuth2 for web servers here, the flow consists of the following steps: Your application redirects a browser to a Google URL; the URL includes query parameters that indicate the type of access being requested. The result is an authorization code, which Google returns to...
clojure,ring,compojure,http-kit
You can use compojure's routes function. You can also pass several handlers to defroutes, an example is provided below: (defroutes get-routes (GET "/events" [] "Event API") (GET "/" [] "Welcome")) (defroutes post-routes (POST "/events" [] "Post Event API")) (def all-routes (routes get-routes post-routes)) (defn -main [] (run-server all-routes {:port 5000}))...
Ok, after much 'googling' and experimentation I seem to have come up with some reasonable solutions to my problems. I'm very new to Clojure and I followed along with the example from this excellent video tutorial. Then I amended the example because I wanted to try and deploy the app...
hum... it is not perfect, but I'm going with: (GET "/details/:id" req (details-page (-> req :params :id) req)) this snippet works, and solves my problem, but I would love something simpler (DRY)....
The Lein-Ring plugin uses an embedded Jetty web server, while Aleph uses the asynchronous Netty web server. The aleph.http/wrap-aleph-handler middleware is designed only to work with a Netty server started with aleph.http/start-http-server function.
Try: (vb/post-page-draw email (Long. id)) ...
unit-testing,clojure,ring,compojure,midje
I discovered today that I had my scopes confused - the let block introducing response was outside of the fact call that included the provided. Thus the response was created before the provided was invoked. Working code which passed this early test instead used the against-background call (facts "It returns...
javascript,clojurescript,compojure,ring,cljsbuild
The compiler is optimized for generating one file per app. You could use multiple builds to do something like what you want, but you would have common code and blobs in both pages (builds), which is not optimal.
authentication,clojure,compojure
Your approach looks somewhat strange to me. You assign auth/handle-authentication to :unauthorized, but the handler function assigned to :unauthorized is called when an incoming request could not be authorized. If I understand you correctly, you want either basic auth or authentication by a third-party supplied cookie where this should be...
clojure,compojure,korma,sqlkorma
Ring responses can be either a map or a string. If they are a map then they use a few keys such as :status and :body to define the response and set cookies etc. You may want to explicitly convert your response from a Clojure sequence (edn) to JSON by...
Ok, so the way to do it is with a regular expression and a context: (defroutes routes (context ["/:base-route" :base-route (re-pattern base-route)] [base-route] (GET "/user" [] (str "base: " base-route " user")) (GET "/settings" [] (str "base: " base-route " settings")))) ...
clojure,ring,compojure,csrf-protection
The problem was that ring-defaults (which replaces the compojure.handler namespace in compojure >= 1.2) automatically uses ring anti-forgery in the usual mode of use: (defroutes app-routes (GET "/" [] (generate-string {:csrf-token *anti-forgery-token*})) (POST "/send" [email] "ok") (resources "/") (not-found "Not Found")) (def app (-> app-routes (wrap-defaults site-defaults))) So two anti-forgery...
clojure,type-conversion,ring,compojure
This is not currently possible with only Compojure. You could use Prismatic schema coercion. (require '[schema.core :as s]) (require '[schema.coerce :as c]) (require '[compojure.core :refer :all]) (require '[ring.middleware.params :as rparams]) (def data {:para1 s/Str :para2 s/Int s/Any s/Any}) (def data-coercer (c/coercer data c/string-coercion-matcher )) (def get-uri (GET "/uri" r (let...
clojure,basic-authentication,compojure
You can provide a totally different credential-fn, or stick to the demo where credential-fn is implemented using cemerick.friend.credentials/bcrypt-credential-fn. Read the doc of bcrypt-credential-fn at https://github.com/cemerick/friend/blob/master/src/cemerick/friend/credentials.clj, it is quite long. It expects a load-credentials-fn that loads a user given a username string, then checks if the password matches. In the demo,...
OK so I resolved my issue, the problem was the way my program was being executed in Heroku. My Procfile previously: web: lein run -m myapp.core all I did is change it to: web: java $JVM_OPTS -jar myapp.jar basically I had to execute my program as a compiled jar....
clojure,docker,compojure,dockerfile
Because ring-server is primarily meant for development, it tries to open a browser when the server starts. This fails with a java.awt.HeadlessException on platforms without a GUI. You'll want to set the :open-browser? option to false to prevent this.
compojure's destructuring tries to access the query/form parameter :req in your example, not the whole request. You have two possibilities: (POST "..." req ...) and (POST "..." [something :as req] ...) Both store the request in req, the second variant allows you to still use destructuring , though....