- Assumptions
- Benefits
- The Recipe—Code
- Testing the Solution
- Notes on the Recipe
- Conclusion
Testing the Solution
Let’s give it a run.
In the command prompt, change back to the parent directory of your project and start the server using Leiningen:
lein ring server-headless 4000
Note that we are using the server-headless parameter to the lein ring command. This starts the server without opening a web browser. Had we merely run (as a hypothetical) lein ring server 4000, a new web browser would have opened. (But because we’re about to use curl to interact with the website, a browser would have gotten in the way.)
Open a new command window and type:
curl http://localhost:4000/1
You should get a response like:
get called: 1
Now enter:
curl -X DELETE http://localhost:4000/4
You should get a response like:
delete called: 4
Now enter:
curl -X POST -d "id=2" http://localhost:4000/3
You should get a response like:
post called: 3 {"id" "2"}
Now enter:
curl -X PUT -d "id=2" http://localhost:4000/3
You should now get something similar to:
put called with params: {:ssl-client-cert nil, :remote-addr "0:0:0:0:0:0:0:1%0", :scheme :http, :query-params {}, :context "/3", :form-params {"id" "2"}, :request-method :put, :query-string nil, :route-params {:id "3"}, :content-type "application/x-www-form-urlencoded", :path-info "/", :uri "/3", :server-name "localhost", :params {:id "3", "id" "2"}, :headers {"user-agent" "curl/7.27.0", "content-type" "application/ x-www-form-urlencoded", "content-length" "4", "accept" "*/*", "host" "localhost:4000"}, :content-length 4, :server-port 4000, :character-encoding nil, :body #<HttpInput org.eclipse.jetty.server.HttpInput@cfefc0>} Julians-MacBook-Pro:~
You can see a large amount of information is in the parameter map req. This also demonstrates the powerful, dynamic, interactive nature of running Compojure with the Leiningen plug-in. You can modify the file and save it, and your changes are accessible instantly to the web browser. (We could also have done all of this on the REPL—but we’ll save that for another day.)