<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>Servant.API.Sub</title><linkhref="ocean.css"rel="stylesheet"type="text/css"title="Ocean"/><scriptsrc="haddock-util.js"type="text/javascript"></script><scripttype="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Servant-API-Sub.html");};
</script></head><body><divid="package-header"><ulclass="links"id="page-menu"><li><ahref="src/Servant-API-Sub.html">Source</a></li><li><ahref="index.html">Contents</a></li><li><ahref="doc-index.html">Index</a></li></ul><pclass="caption">servant-0.2: A family of combinators for defining webservices APIs and serving them</p></div><divid="content"><divid="module-header"><tableclass="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><pclass="caption">Servant.API.Sub</p></div><divid="synopsis"><pid="control.syn"class="caption expander"onclick="toggleSection('syn')">Synopsis</p><ulid="section.syn"class="hide"onclick="toggleSection('syn')"><liclass="src short"><spanclass="keyword">data</span> path <ahref="#t::-62-">:></a> a = (<ahref="Servant.html#t:Proxy">Proxy</a> path) <ahref="#v::-62-">:></a> a</li></ul></div><divid="interface"><h1>Documentation</h1><divclass="top"><pclass="src"><spanclass="keyword">data</span> path <aname="t::-62-"class="def">:></a> a <spanclass="fixity">infixr 9</span><spanclass="rightedge"></span><ahref="src/Servant-API-Sub.html#%3A%3E"class="link">Source</a></p><divclass="doc"><p>The contained API (second argument) can be found under <code>("/" ++ path)</code>
(path being the first argument).</p><p>Example:</p><pre>-- GET /hello/world
-- returning a JSON encoded World value
type MyApi = "hello" :>"world" :> Get World</pre></div><divclass="subs constructors"><pclass="caption">Constructors</p><table><tr><tdclass="src">(<ahref="Servant.html#t:Proxy">Proxy</a> path) <aname="v::-62-"class="def">:></a> a <spanclass="fixity">infixr 9</span><spanclass="rightedge"></span></td><tdclass="doc empty"> </td></tr></table></div><divclass="subs instances"><pid="control.i::-62-"class="caption collapser"onclick="toggleSection('i::-62-')">Instances</p><divid="section.i::-62-"class="show"><table><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> s, <ahref="Servant-Utils-Links.html#t:VLinkHelper">VLinkHelper</a> * e) =><ahref="Servant-Utils-Links.html#t:VLinkHelper">VLinkHelper</a> * (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> s e)</td><tdclass="doc empty"> </td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> capture, <ahref="Servant-Common-Text.html#t:FromText">FromText</a> a, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-Capture.html#t:Capture">Capture</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * capture a) sublayout)</td><tdclass="doc"><p>If you use <code><ahref="Servant-API-Capture.html#t:Capture">Capture</a></code> in one of the endpoints for your API,
this automatically requires your server-side handler to be a function
that takes an argument of the type specified by the <code><ahref="Servant-API-Capture.html#t:Capture">Capture</a></code>.
This lets servant worry about getting it from the URL and turning
it into a value of the type you specify.</p><p>You can control how it'll be converted from <code><ahref="https://hackage.haskell.org/package/text-1.2.0.0/docs/Data-Text.html#t:Text">Text</a></code> to your type
by simply providing an instance of <code><ahref="Servant-Common-Text.html#t:FromText">FromText</a></code> for your type.</p><p>Example:</p><pre>type MyApi = "books" :> Capture "isbn" Text :> Get Book
server :: Server MyApi
server = getBook
where getBook :: Text -> EitherT (Int, String) IO Book
getBook isbn = ...</pre></td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> sym, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryFlag">QueryFlag</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> sym) sublayout)</td><tdclass="doc"><p>If you use <code><code><ahref="Servant-API-QueryParam.html#t:QueryFlag">QueryFlag</a></code>"published"</code> in one of the endpoints for your API,
this automatically requires your server-side handler to be a function
that takes an argument of type <code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Bool.html#t:Bool">Bool</a></code>.</p><p>Example:</p><pre>type MyApi = "books" :> QueryFlag "published" :> Get [Book]
server :: Server MyApi
server = getBooks
where getBooks :: Bool -> EitherT (Int, String) IO [Book]
getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...</pre></td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> sym, <ahref="Servant-Common-Text.html#t:FromText">FromText</a> a, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryParams">QueryParams</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * sym a) sublayout)</td><tdclass="doc"><p>If you use <code><code><ahref="Servant-API-QueryParam.html#t:QueryParams">QueryParams</a></code>"authors" Text</code> in one of the endpoints for your API,
this automatically requires your server-side handler to be a function
that takes an argument of type <code>[<code>Text</code>]</code>.</p><p>This lets servant worry about looking up 0 or more values in the query string
associated to <code>authors</code> and turning each of them into a value of
the type you specify.</p><p>You can control how the individual values are converted from <code>Text</code> to your type
by simply providing an instance of <code><ahref="Servant-Common-Text.html#t:FromText">FromText</a></code> for your type.</p><p>Example:</p><pre>type MyApi = "books" :> QueryParams "authors" Text :> Get [Book]
server :: Server MyApi
server = getBooksBy
where getBooksBy :: [Text] -> EitherT (Int, String) IO [Book]
getBooksBy authors = ...return all books by these authors...</pre></td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> sym, <ahref="Servant-Common-Text.html#t:FromText">FromText</a> a, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryParam">QueryParam</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * sym a) sublayout)</td><tdclass="doc"><p>If you use <code><code><ahref="Servant-API-QueryParam.html#t:QueryParam">QueryParam</a></code>"author" Text</code> in one of the endpoints for your API,
this automatically requires your server-side handler to be a function
that takes an argument of type <code><code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#t:Maybe">Maybe</a></code><code>Text</code></code>.</p><p>This lets servant worry about looking it up in the query string
and turning it into a value of the type you specify, enclosed
in <code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#t:Maybe">Maybe</a></code>, because it may not be there and servant would then
hand you <code><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#v:Nothing">Nothing</a></code>.</p><p>You can control how it'll be converted from <code>Text</code> to your type
by simply providing an instance of <code><ahref="Servant-Common-Text.html#t:FromText">FromText</a></code> for your type.</p><p>Example:</p><pre>type MyApi = "books" :> QueryParam "author" Text :> Get [Book]
server :: Server MyApi
server = getBooksBy
where getBooksBy :: Maybe Text -> EitherT (Int, String) IO [Book]
getBooksBy Nothing = ...return all books...
getBooksBy (Just author) = ...return books by the given author...</pre></td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-Aeson-Types.html#t:FromJSON">FromJSON</a> a, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-ReqBody.html#t:ReqBody">ReqBody</a> * a) sublayout)</td><tdclass="doc"><p>If you use <code><ahref="Servant-API-ReqBody.html#t:ReqBody">ReqBody</a></code> in one of the endpoints for your API,
this automatically requires your server-side handler to be a function
that takes an argument of the type specified by <code><ahref="Servant-API-ReqBody.html#t:ReqBody">ReqBody</a></code>.
This lets servant worry about extracting it from the request and turning
it into a value of the type you specify.</p><p>All it asks is for a <code><ahref="https://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-Aeson-Types.html#t:FromJSON">FromJSON</a></code> instance.</p><p>Example:</p><pre>type MyApi = "books" :> ReqBody Book :> Post Book
server :: Server MyApi
server = postBook
where postBook :: Book -> EitherT (Int, String) IO Book
postBook book = ...insert into your db...</pre></td></tr><tr><tdclass="src">(<ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:KnownSymbol">KnownSymbol</a> path, <ahref="Servant-Server.html#t:HasServer">HasServer</a> sublayout) =><ahref="Servant-Server.html#t:HasServer">HasServer</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> path sublayout)</td><tdclass="doc"><p>Make sure the incoming request starts with <code>"/path"</code>, strip it and
pass the rest of the request path to <code>sublayout</code>.</p></td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-Capture.html#t:Capture">Capture</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * capture a) sublayout) = a -><ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryFlag">QueryFlag</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> sym) sublayout) = <ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Bool.html#t:Bool">Bool</a> -><ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryParams">QueryParams</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * sym a) sublayout) = [a] -><ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-QueryParam.html#t:QueryParam">QueryParam</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> * sym a) sublayout) = <ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Maybe.html#t:Maybe">Maybe</a> a -><ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a> * (<ahref="Servant-API-ReqBody.html#t:ReqBody">ReqBody</a> * a) sublayout) = a -><ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><spanclass="keyword">type</span><ahref="Servant-Server.html#t:Server">Server</a> (<ahref="Servant-API-Sub.html#t::-62-">(:>)</a><ahref="https://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-TypeLits.html#t:Symbol">Symbol</a> path sublayout) = <ahref="Servant-Server.html#t:Server">Server</a> sublayout</td><tdclass="doc empty"> </td></tr></table></div></div></div></div></div><divid="footer"><p>Produced by <ahref="http://www.haskell.org/haddock/">Haddock</a> version 2.15.0</p></div></body></html>