Skip to content

Instantly share code, notes, and snippets.

@parambirs
Created October 20, 2015 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parambirs/efe8ddc0f7d57ca10de1 to your computer and use it in GitHub Desktop.
Save parambirs/efe8ddc0f7d57ca10de1 to your computer and use it in GitHub Desktop.
-- set a header:
post "/set-headers" $ do
status status302 -- Respond with HTTP 302 status code
setHeader "Location" "http://www.google.com.au"
-- named parameters:
get "/askfor/:word" $ do
w <- param "word"
html $ mconcat ["<h1>You asked for ", w, ", you got it!</h1>" ]
-- unnamed parameters from a query string or a form:
post "/submit" $ do -- e.g. http://server.com/submit?name=somename
name <- param "name"
text name
-- match a route regardless of the method
matchAny "/all" $ do
text "matches all methods"
-- handler for when there is no matched route
-- (this should be the last handler because it matches all routes)
notFound $ do
text "there is no such route."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment