-
Notifications
You must be signed in to change notification settings - Fork 65
Happstack: Request
A Request
represents an HTTP request. This generally means that a user is either asking for data from the server, or trying to give data to the server.
These two methods are generally defined as:
-
GET : Get a file/data from the server.
-
POST : Give data to the server.
In the server, we can ask for the request with the method askRq
. Here is a simple example that I have put together:
reqExample :: ServerPartT IO Response
reqExample =
do req <- askRq
ok $ toResponse $ rqQuery req
(We stuff the value of askRq
into req
, as askRq
will return the type m0 Request
, which unfortunately we cannot call rqQuery
on 😭)
This example can be run in Happstack with the following main
method:
code :: String
code = "example"
main :: IO ()
main = do
simpleHTTP nullConf $
msum [ dir code $ reqExample
]
Now, let's run the example. When the server is running, we can now visit the page http://localhost:8000/example/
. What do we see? Nothing! Fantastic!
We see nothing because we are asking for the query parameters from the Request
. This request has none, though.
Now, revisit the server, but use the URL http://localhost:8000/graph-fb/?happiness=chocolate,peanutbutter
.
What do you see? The truth? Me too.
To takeaway: The 'current' Request
can always be accessed.
rqSecure rqMethod rqSecure rqMethod rqPaths rqUri rqQuery rqInputsQuery rqInputsBody rqCookies rqVersion rqHeaders rqBody rqPeer