-
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!
Look here to see which methods we can use to dissect a request.
To takeaway: The 'current' Request
can always be accessed.