rest-core-0.38: Rest API library.

Safe HaskellNone
LanguageHaskell98

Rest.Schema

Contents

Description

This module contains data types and combinators for defining a Schema for your Resource. A Schema has three type parameters, specifying the identifiers for a single resource, a listing, and a top-level (static) action. After routing, these identifiers will be passed to the Handler.

Synopsis

A set of combinators for creating schemas.

Top level

withListing :: mid -> Step sid mid aid -> Schema sid mid aid Source

A schema with a top level listing.

noListing :: Step sid mid aid -> Schema sid mid aid Source

A schema with no top level listing.

singleton :: sid -> Step sid mid aid -> Schema sid mid aid Source

A schema with a singleton at the top level.

Named endpoints

named :: [(String, Endpoint sid mid aid)] -> Step sid mid aid Source

A list of named endpoints.

static :: aid -> Endpoint sid mid aid Source

A top level action endpoint for this resource.

single :: sid -> Endpoint sid mid aid Source

A singleton resource endpoint.

singleBy :: (String -> sid) -> Endpoint sid mid aid Source

A single resource endpoint with a string identifier.

singleRead :: (Show a, Read a, Info a) => (a -> sid) -> Endpoint sid mid aid Source

A single resource endpoint with an identifier that can be read.

listing :: mid -> Endpoint sid mid aid Source

A listing endpoint.

listingBy :: (String -> mid) -> Endpoint sid mid aid Source

A listing endpoint with a string identifier.

listingRead :: (Show a, Read a, Info a) => (a -> mid) -> Endpoint sid mid aid Source

A listing with an identifier that can be read.

Unnamed endpoints

unnamedSingle :: (String -> sid) -> Step sid mid aid Source

An unnamed single resource with a string identifier.

unnamedSingleRead :: (Show a, Read a, Info a) => (a -> sid) -> Step sid mid aid Source

An unnamed single resource with an identifier that can be read.

unnamedListing :: (String -> mid) -> Step sid mid aid Source

An unnamed listing with a string identifier.

unnamedListingRead :: (Show a, Read a, Info a) => (a -> mid) -> Step sid mid aid Source

An unnamed listing with an identifier that can be read.

The core schema data types.

data Schema sid mid aid Source

A Schema describes how (part of the) route to a resource looks, and returns an identifier for a single resource (sid), many resources (mid) or a static action (aid). The first argument specifies the top level resource (no path segments). The second specifies a what happens at the first step in the path.

Constructors

Schema (Maybe (Cardinality sid mid)) (Step sid mid aid) 

data Step sid mid aid Source

A step in the routing of a resource. A part of the uri either identifies a Named resource, or an Unnamed resource. Named resources can be static actions (Left) or one or many singletons or by's.

Constructors

Named [(String, Endpoint sid mid aid)] 
Unnamed (Cardinality (Id sid) (Id mid)) 

data Cardinality s m Source

Specifies if we're identifying a single resource, or many (a listing).

Constructors

Single s 
Many m 

data Getter id Source

A Getter can either be a Singleton (there is only one) or it can be identified By an Identifier.

Constructors

Singleton id 
By (Id id) 

data Id id Source

An identification of an item in a resource. It contains a dictionary describing how to identify the resource, and a function for this identification type to an id.

Constructors

forall a . Id (Ident a) (a -> id) 

type Endpoint sid mid aid = Either aid (Cardinality (Getter sid) (Getter mid)) Source

A named endpoint: an static action, a single item of many items.