servant-hateoas-0.2.2: HATEOAS extension for servant
Safe HaskellSafe-Inferred
LanguageGHC2021

Servant.Hateoas.Resource

Synopsis

Resource

Construction

class ToResource api res a where Source #

Class for converting values of a to their respective Resource-Representation.

Minimal complete definition

toResource | toResource'

Methods

toResource :: a -> res a Source #

Converts a value into it's Resource-Representation.

toResource' :: Proxy api -> Proxy res -> a -> res a Source #

Like toResource but takes proxies for ambiguity.

Instances

Instances details
(Related a, HasField (IdSelName a) a id, IsElem (GetOneApi a) api, HasLink (GetOneApi a), MkLink (GetOneApi a) Link ~ (id -> Link), BuildRels api (Relations a) a, Resource HALResource) => ToResource (api :: Type) HALResource a Source # 
Instance details

Defined in Servant.Hateoas.ContentType.HAL

class ToCollection api res a where Source #

Class for converting multiple values of a to their respective collection-like representation.

Minimal complete definition

toCollection | toCollection'

Methods

toCollection :: Foldable f => f a -> res a Source #

Converts many values into their Collection-Representation.

toCollection' :: Foldable f => Proxy api -> Proxy res -> f a -> res a Source #

Like toCollection but takes proxies for ambiguity.

Modification

class Resource res where Source #

Class for resources that carry Hypermedia-Relations.

Methods

addLink :: (String, Link) -> res a -> res a Source #

Add a relation (rel, link) to a resource.

Instances

Instances details
Resource CollectionItem Source # 
Instance details

Defined in Servant.Hateoas.ContentType.Collection

Methods

addLink :: forall (a :: k). (String, Link) -> CollectionItem a -> CollectionItem a Source #

Resource CollectionResource Source # 
Instance details

Defined in Servant.Hateoas.ContentType.Collection

Methods

addLink :: forall (a :: k). (String, Link) -> CollectionResource a -> CollectionResource a Source #

Resource HALResource Source # 
Instance details

Defined in Servant.Hateoas.ContentType.HAL

Methods

addLink :: forall (a :: k). (String, Link) -> HALResource a -> HALResource a Source #

class Resource res => EmbeddingResource res where Source #

Class for Resources that can embed other resources.

Methods

embed :: ToJSON e => (String, e) -> res a -> res a Source #

Embed a resource b with its relation rel as tuple (rel, b).

Instances

Instances details
EmbeddingResource HALResource Source # 
Instance details

Defined in Servant.Hateoas.ContentType.HAL

Methods

embed :: forall e (a :: k). ToJSON e => (String, e) -> HALResource a -> HALResource a Source #

class Resource res => CollectingResource res where Source #

Class for Resources that can collect multiple resources.

Methods

collect :: a -> res a -> res a Source #

Collect a resource into the collection.

Hypermedia-Relations

Type

data HRel Source #

Data-Kind for Hypermedia-Relations.

Constructors

HRel 

Fields

Instances

Instances details
BuildRels api ('[] :: [HRel]) a Source # 
Instance details

Defined in Servant.Hateoas.Resource

Methods

buildRels :: Proxy '[] -> Proxy api -> a -> [(String, Link)] Source #

(KnownSymbol relName, HasField selName a id, HasLink endpoint, IsElem endpoint api, MkLink endpoint Link ~ (id -> Link), BuildRels api rs a) => BuildRels api ('HRel relName selName endpoint ': rs) a Source # 
Instance details

Defined in Servant.Hateoas.Resource

Methods

buildRels :: Proxy ('HRel relName selName endpoint ': rs) -> Proxy api -> a -> [(String, Link)] Source #

Class

class Related a Source #

Types that have Hypermedia-Relations.

Associated Types

type IdSelName a :: Symbol Source #

Name of the record selector that holds the resources identifier

type GetOneApi a :: Type Source #

Servant-Endpoint for retrieving one a by its identifier

type CollectionName a :: Symbol Source #

Name for collected values

type CollectionName a = "items"

type Relations a :: [HRel] Source #

List of all relations a has

Construction

class BuildRels api rs a where Source #

Class for deriving Hypermedia-Relations for types.

Methods

buildRels :: Proxy rs -> Proxy api -> a -> [(String, Link)] Source #

Instances

Instances details
BuildRels api ('[] :: [HRel]) a Source # 
Instance details

Defined in Servant.Hateoas.Resource

Methods

buildRels :: Proxy '[] -> Proxy api -> a -> [(String, Link)] Source #

(KnownSymbol relName, HasField selName a id, HasLink endpoint, IsElem endpoint api, MkLink endpoint Link ~ (id -> Link), BuildRels api rs a) => BuildRels api ('HRel relName selName endpoint ': rs) a Source # 
Instance details

Defined in Servant.Hateoas.Resource

Methods

buildRels :: Proxy ('HRel relName selName endpoint ': rs) -> Proxy api -> a -> [(String, Link)] Source #

selfLink :: forall api a id. (Related a, HasField (IdSelName a) a id, IsElem (GetOneApi a) api, HasLink (GetOneApi a), MkLink (GetOneApi a) Link ~ (id -> Link)) => Proxy api -> a -> (String, Link) Source #

Generates the pair ("self", link) where link is the Link to a itself.

relatedLinks :: forall api a. (Related a, BuildRels api (Relations a) a) => Proxy api -> a -> [(String, Link)] Source #

Generates pairs (rel, link) for all related resources as defined with Relations.

defaultLinks :: forall api a id. (Related a, HasField (IdSelName a) a id, IsElem (GetOneApi a) api, HasLink (GetOneApi a), MkLink (GetOneApi a) Link ~ (id -> Link), BuildRels api (Relations a) a) => Proxy api -> a -> [(String, Link)] Source #

Generate Hypermedia-Links by default.

defaultLinks api x = selfLink api x : relatedLinks api x