getQuery, getSimpleQuery

HTTP related types


getQuery :: HttpRequest String -> Maybe (FilePath, [(String, String)])
getSimpleQuery :: HttpRequest String -> Maybe (FilePath, String)

These functions extract the most important information from an HTTP request.

getQuery should be used when the request is from a web page containing a form in a <FORM> element. The request method can be either GET or POST.

getSimpleQuery should be used when a query is submitted from a web page containing an <ISINDEX> element.

The result, if the request is well formed, is a pair containing the document path (that was part of the URL) and the submitted data. Special characters that were encoded in the request are decoded (as with decode or decodeQuery).


If a form like

  <FORM ACTION="http://myserver:8080/Movie/Search" METHOD=GET>
    Actor: <INPUT name=actor> <br>
    Year: <INPUT name=year maxlength=4>
    <INPUT type=Submit value="Find Movie"> 

is submitted with some actor and year filled in, the browser constructs an URL like


Applying getQuery to a request containing this URL will yield the following result:

  Just ("/Movie/Search",[("year","1999"),("actor","Willis, Bruce")])

The result will be the same if the request method is changed to POST (but the form data will be put in another part of the request, and will thus not be visible in the URL).

See Also

Hints on how form data is encoded in URLs: decodeQuery.

Quick reference manual on HTML forms.