-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Lens-based HTTP toolkit -- @package nero @version 0.1 -- | This module is mainly intended to be used for rare occassions. -- Nero.Request and Nero.Payload should provide everything -- you need for HTTP parameters. module Nero.Param -- | A Map with multiple values. Also known as a MultiDict -- in most web frameworks. data MultiMap -- | A Traversal' of the values of a given HTTP parameter. class Param a param :: Param a => Text -> Traversal' a Text -- | Encode a MultiMap with the typical query string format. This is -- useful to render MultiMaps when testing. The web server adapter -- for Nero should do this for you in the real application. encodeMultiMap :: MultiMap -> ByteString instance Eq MultiMap instance Param MultiMap instance At MultiMap instance Ixed MultiMap instance Wrapped MultiMap instance Monoid MultiMap instance Show MultiMap module Nero.Url -- | Composite type of a Scheme, Host, Path, -- Query. data Url -- | The scheme given in the Url, i.e. http or -- https. data Scheme -- | The host name of a Url. type Host = ByteString -- | Path after the host name in a Url. type Path = Text -- | The query string in the form of a MultiMap. type Query = MultiMap -- | Lens' for types with an Url. class HasUrl a url :: HasUrl a => Lens' a Url -- | Traversal' to obtain the Url of types with -- Location. class Location a location :: Location a => Traversal' a Url -- | Lens' for types with a Host. class HasHost a host :: HasHost a => Lens' a Host -- | Lens' for types with a Path. class HasPath a path :: HasPath a => Lens' a Path -- | Lens' for types with a Query. class HasQuery a query :: HasQuery a => Lens' a Query -- | A Traversal' of the values of a given HTTP parameter. class Param a param :: Param a => Text -> Traversal' a Text -- | Empty Url useful for testing. dummyUrl :: Url instance Eq Scheme instance Eq Url instance Param Url instance HasQuery Url instance HasPath Url instance HasHost Url instance Show Url instance Show Scheme -- | This module is mostly used for routing Requests based on -- their Path. It can also be used for matching with any -- arbitrary Text source. module Nero.Match -- | A pattern. type Pattern = [Pat] -- | One part of Pattern. data Pat -- | A monomorphic wrapper for polymorphic results. Makes it easier to deal -- with lists of matches. data Value -- | A Pattern that captures anything. text :: Pattern -- | Creates a Pattern from the given text discarding the match. -- When writing Patterns directly in source code, you may prefer -- to use the IsString instance of Pattern. text_ :: Text -> Pattern -- | A Pattern that captures any Int. int :: Pattern -- | Represents a Prism' from arbitrary Text to a -- Target result. type Matcher a = Prism' Text a -- | Helper class to support polymorphic target results. class Target a target :: Target a => Prism' [Value] a -- | Creates a Matcher from the given Pattern. match :: Target a => Pattern -> Matcher a instance Show Pat instance Eq Pat instance Show Value instance Eq Value instance Target (Text, Int) instance Target (Text, Text) instance Target Int instance Target Text instance IsString Pattern module Nero.Payload -- | Contains the Body and any metadata associated with it. data Payload payloadText :: Encoding -> Body -> Payload -- | Indicates a Text encoding. data Encoding utf8Encoding :: Encoding -- | A Traversal' for types with a Payload. class Payloaded a payload :: Payloaded a => Traversal' a Payload -- | It's the main data associated with the Payload of -- Request or a Response. type Body = ByteString -- | Get the Body for types with one. class HasBody a body :: HasBody a => a -> Body -- | A MultiMap in the context of a form. type Form = MultiMap -- | A Prism' to obtain a Form from a Payload and make -- Payload from a Form. _Form :: Prism' Payload Form -- | A Traversal' to access a potential Form. class Formed a form :: Formed a => Traversal' a Form -- | A Payload with an empty Form useful for testing. dummyPayloadForm :: Payload instance Show Encoding instance Eq Encoding instance Show Payload instance Eq Payload instance Param Payload instance Formed Payload instance HasBody Payload module Nero.Request -- | An HTTP Request. data Request -- | Show Request method. method :: Request -> ByteString -- | Prism' to filter GET Requests. -- --
--   >>> dummyRequest ^? _GET <&> method
--   Just "GET"
--   
--   >>> dummyRequestForm ^? _GET <&> method
--   Nothing
--   
_GET :: Prism' Request Request -- | Prism' to filter for POST Requests. -- --
--   >>> dummyRequest ^? _POST <&> method
--   Nothing
--   
--   >>> dummyRequestForm ^? _POST <&> method
--   Just "POST"
--   
_POST :: Prism' Request Request -- | This Traversal lets you traverse every HTTP parameter -- regardless of whether it's present in the query string or in -- the form encoded body of a POST Request. In the -- rare case where there are HTTP parameters in both, every parameter is -- still being traversed starting from the /query string/. -- -- You might want to use param for traversing a specific -- parameter. -- --
--   >>> let request = dummyRequestForm & query . at "name" ?~ ["hello", "out"] & form  . at "name" ?~ ["there"]
--   
--   >>> foldOf params request ^? ix "name"
--   Just ["hello","out","there"]
--   
params :: Traversal' Request MultiMap -- | An empty GET request useful for testing. dummyRequest :: Request -- | An empty POST request with an empty form encoded body useful -- for testing. dummyRequestForm :: Request instance Show Request instance Eq Request instance Formed Request instance Param Request instance Payloaded Request instance HasQuery Request instance HasPath Request instance HasHost Request instance HasUrl Request module Nero.Response -- | An HTTP response. data Response -- | Creates an 200 OK response from the given text. It -- automatically encodes the text to 'utf-8'. The Mime type is -- text/plain. ok :: Text -> Response -- | Creates an 301 Moved Permanently response with the -- Location corresponding to the given Url. movedPermanently :: Url -> Response -- | The HTTP status code and description. data Status -- | Obtain the Status from a Response. status :: Response -> Status instance Show Response instance Eq Response instance Show Status instance HasBody Response instance Location Response module Nero.Application -- | Redirect with slash appended URL if only a trailing slash is needed -- for successful matching, otherwise it responds normally. -- --
--   >>> let mkRequest p = dummyRequest & host .~ "example.com" & path .~ p
--   
--   >>> let matcher = match $ "/hello/" <> text <> "/"
--   
--   >>> let respond name = ok $ "<h1>Hello " <> name <> "</h1>"
--   
--   >>> let app = slashRedirect matcher respond
--   
-- --
--   >>> app (mkRequest "/hello/there") <&> status
--   Just "301 Moved Permanently"
--   
--   >>> app (mkRequest "/hello/there") >>= preview location
--   Just "http://example.com/hello/there/"
--   
-- --
--   >>> app (mkRequest "/hello/there/") <&> status
--   Just "200 OK"
--   
--   >>> app (mkRequest "/hello/there/") <&> body
--   Just "<h1>Hello there</h1>"
--   
-- --
--   >>> app $ mkRequest "/bye/"
--   Nothing
--   
slashRedirect :: Target a => Matcher a -> (a -> Response) -> Request -> Maybe Response -- | This module centralizes the main modules exported by Nero such that -- it's straightforward to write simple Nero applications with a single -- import. It also exports frequently used functions from -- Control.Lens, Control.Applicative and -- Data.Monoid. module Nero