-
Notifications
You must be signed in to change notification settings - Fork 70
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.
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
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.
These two actions are generally defined as:
-
GET : Get a file/data from the server. -
POST : Give data to the server.