Missing form parameters in Compojure POST request

前端 未结 4 1692
北荒
北荒 2021-01-01 18:30

I\'m having problems getting the form parameters in the following Compojure example:

(ns hello-world
  (:use compojure.core, ring.adapter.jetty)
  (:require          


        
相关标签:
4条回答
  • 2021-01-01 18:41

    here is a runnable example as of 17 Nov 2012:

    • https://github.com/dustingetz/sandbox/tree/master/clojure/compojure-bootstrap
    0 讨论(0)
  • 2021-01-01 18:42

    Have you taken into account this:

    As of version 0.6.0, Compojure no longer adds default middleware to routes. This means you must explicitly add the wrap-params and wrap-cookies middleware to your routes.

    Source: https://github.com/weavejester/compojure

    I tried your example with my current setup and it worked. I have included the following: require [compojure.handler :as handler] and (handler/api routes).

    0 讨论(0)
  • 2021-01-01 18:56

    You can just give a list of parameters; compojure will automatically get them out of POST/GET params accordingly. If you need to do more complex stuff you can, but I've never looked into how. For example, here's a snippet from the code for 4clojure:

    (POST "/problems/submit" [title tags description code]
      (create-problem title tags description code))
    
    0 讨论(0)
  • 2021-01-01 19:01

    This is a great example of how to handle parameters

    (ns example2
      (:use [ring.adapter.jetty             :only [run-jetty]]
        [compojure.core                 :only [defroutes GET POST]]
        [ring.middleware.params         :only [wrap-params]]))
    
    (defroutes routes
      (POST "/" [name] (str "Thanks " name))
      (GET  "/" [] "<form method='post' action='/'> What's your name? <input type='text' name='name' /><input type='submit' /></form>"))
    
    (def app (wrap-params routes))
    
    (run-jetty app {:port 8080})
    

    https://github.com/heow/compojure-cookies-example

    See under Example 2 - Middleware is Features

    0 讨论(0)
提交回复
热议问题