liveBook · Manning

Application

As explained in Learn Haskell by Example

Application is the WAI web-application interface representing a function that handles an HTTP request and produces a response.

A WAI Application connects a web server implementation to request-handling code. It receives a request and response callback, computes a response, and invokes the callback. section 17.2.1

In a Servant server, an Application is produced from an API description and its handlers:

  • Use serve with a Proxy for the API and the implemented Server to produce an Application. section 17.2.1
  • Wrap an Application with Middleware when adding behavior without changing the Servant API type. section 17.2.2

Creating and running an application

mkApiServer :: Connection -> Application mkApiServer = serve todoApi . mkTodoApiServer main :: IO () main = do let port = 9001 withConnection ":memory:" $ \dbConn -> do setupDb dbConn run port (mkApiServer dbConn) This starts a Servant todo-list API on port 9001, where requests such as GET /entries and POST /add can be tested. section 17.2.1

How Learn Haskell by Example covers it

How deep it goes
Defines the request-callback type, application construction, startup, and middleware wrapping without detailing server internals.
Examples
Uses a todo-list API with GET, POST, and PATCH requests, an in-memory database, and a root HTML route.
What it assumes
Assumes a Servant API, server handlers, database connection, and basic Haskell module and executable setup.
What you can do after
Build it from scratch by converting Servant handlers into an Application and running it with Warp.
How it connects
Ties together Servant, WAI, Warp, middleware, HTTP requests, response callbacks, and Proxy.

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.