(gist.github.com anyone?)
$ curl -X POST \
-H "content-type: text/plain" \
-d "Hello, world!" \
http://server/snippets/
# Should return HTTP 302 with a Location header for us to follow
$ curl -X GET http://server/snippets/1234
Hello, world!
- Ring is a simple (conceptual) framework for building web applications.
- It also has some useful code.
- Request maps:
{:server-port 8080
:server-name "localhost"
:uri "/foo/bar/baz"
:scheme :https
:headers {"content-type" "text/plain"
:body <some Java stream object>}
- Response maps:
{:status 200
:headers ["content-type" "text/plain"]
:body "Hello, world!"}
- Creating and modifying responses
- The functions in
ring.util.response
are useful
- The functions in
- Straightforward requirements:
- Take a single parameter (request map)
- Return a response map
(fn [req]
{:status 200 :body ""})
- Sketch out the GET and POST handlers...
- ...in a Compojure
defroutes
setup
- ...in a Compojure
reset!
andswap!
- We need them, Java has them.
- Write the rest of the code!
- Web pages
- URL shortening
- Durable datastore
- Automatic content conversion (if possible)
- e.g. JSON <--> EDN, JSON --> HTML, ...