web-routes-0.23.1: Library for maintaining correctness and composability of URLs within an application.

Web.Routes.Site

Synopsis

Documentation

data Site url a Source

A site groups together the three functions necesary to make an application:

  • A function to convert from the URL type to path segments.
  • A function to convert from path segments to the URL, if possible.
  • A function to return the application for a given URL.

There are two type parameters for Site: the first is the URL datatype, the second is the application datatype. The application datatype will depend upon your server backend.

Constructors

Site 

Fields

handleSite :: (url -> [(String, String)] -> String) -> url -> a

Return the appropriate application for a given URL.

The first argument is a function which will give an appropriate URL (as a String) for a URL datatype. This is usually constructed by a combination of formatPathSegments and the prepending of an absolute application root.

Well behaving applications should use this function to generating all internal URLs.

formatPathSegments :: url -> ([String], [(String, String)])

This function must be the inverse of parsePathSegments.

parsePathSegments :: [String] -> Either String url

This function must be the inverse of formatPathSegments.

Instances

Functor (Site url) 

setDefault :: url -> Site url a -> Site url aSource

Override the "default" URL, ie the result of parsePathSegments [].

runSiteSource

Arguments

:: String

application root, with trailing slash

-> Site url a 
-> String

path info, leading slash stripped

-> Either String a 

Retrieve the application to handle a given request.