liveBook · Manning

HTTP GET

As explained in Learn Haskell by Example

GET is the HTTP method for requesting a representation of a resource without intending to modify it.

HTTP GET identifies a request method that middleware can use to select a response for an application route. section 17.2.2

A middleware check can:

  • Inspect requestMethod to determine whether the request uses GET. section 17.2.2
  • Inspect pathInfo to determine whether the request targets the root path (/). section 17.2.2
  • Return HTML for a matching root request or delegate other requests to the wrapped application. section 17.2.2

Serving the todo page

A middleware function matches a GET request whose path is /, generates HTML for the todo entries, and otherwise passes control to the API server. section 17.2.2

import Network.HTTP.Types (methodGet)

...

mkAppRoot :: Connection -> Middleware
mkAppRoot dbConn app req responseAct
  | isRootRequest = ...
  | otherwise = app req responseAct
  where
    isRootRequest =
      requestMethod req == methodGet
        && null (pathInfo req)

Inspect the complete root-request predicate, including the methodGet constant, requestMethod comparison, and empty path check. section 17.2.2

How Learn Haskell by Example covers it

How deep it goes
Implements method and path checks with fallback delegation, but does not detail broader HTTP semantics.
Examples
Uses a todo application that serves ranked todo entries as HTML at the root path.
What it assumes
Requires understanding WAI Application functions, request attributes, response callbacks, and basic Haskell middleware types.
What you can do after
Operate/configure middleware that distinguishes root GET requests from requests handled by an API server.
How it connects
Connects HTTP GET with middleware, WAI Application, Request, Response, and Servant APIs.

Also explained in

Compare how 14 books explain HTTP GET →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.