-
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 $ show req
(We stuff the value of askRq
into req
, as askRq
will return the type m0 Request
, which unfortunately we cannot call show
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 we now see is the request you just made, in its entirety! There's quite a lot of information there, but it will soon become easy to understand.
rqSecure rqMethod rqSecure rqMethod rqPaths rqUri rqQuery rqInputsQuery rqInputsBody rqCookies rqVersion rqHeaders rqBody rqPeer
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.