Safe Haskell | None |
---|---|
Language | Haskell2010 |
Entry-point module for this package.
Synopsis
- data Document a
- data ResourceData a
- data ErrorDocument a = ErrorDocument {
- _error :: Error a
- _errorLinks :: Maybe Links
- _errorMeta :: Maybe Meta
- data Included
- data Error a = Error {}
- data Relationship
- data Resource a = Resource {}
- data Relationships
- class (ToJSON a, FromJSON a) => ResourcefulEntity a where
- resourceIdentifier :: a -> Text
- resourceType :: a -> Text
- resourceLinks :: a -> Maybe Links
- resourceMetaData :: a -> Maybe Meta
- resourceRelationships :: a -> Maybe Relationships
- fromResource :: Resource a -> a
- toResource :: a -> Resource a
- class HasIdentifier a where
- identifier :: a -> Identifier
- data Identifier = Identifier {}
- data Links
- data Meta
- class ToJSON a => MetaObject a where
- mkLinks :: [(Rel, Text)] -> Links
- data Pagination = Pagination {}
- newtype PageNum = PageNum {
- getPageNum :: Int
- newtype PageSize = PageSize {
- getPageSize :: Int
- newtype ResourceCount = ResourceCount {}
- indexLinks :: Text -> Pagination -> Links
- mkRelationship :: Maybe Identifier -> Maybe Links -> Maybe Relationship
- mkRelationships :: Relationship -> Relationships
- showLink :: ResourcefulEntity e => e -> Links
- mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Document a
- mkDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Document a
- singleton :: ResourcefulEntity a => a -> ResourceData a
- list :: ResourcefulEntity a => [a] -> ResourceData a
- mkCompoundDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Included -> Document a
- mkCompoundDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Included -> Document a
- mkIncludedResource :: ResourcefulEntity a => a -> Included
- mkSimpleDocument :: ResourcefulEntity a => [a] -> Document a
- mkSimpleDocument' :: ResourceData a -> Document a
- mkMeta :: MetaObject a => a -> Meta
Documentation
The Document
type represents the top-level JSON-API requirement.
data
attribute - the resulting JSON may be either a singleton resource
or a list of resources. See Resource
for the construction.
For more information see: http://jsonapi.org/format/#document-top-level
Instances
Eq a => Eq (Document a) Source # | |
Show a => Show (Document a) Source # | |
Generic (Document a) Source # | |
ToJSON a => ToJSON (Document a) Source # | |
Defined in Network.JSONApi.Document | |
FromJSON a => FromJSON (Document a) Source # | |
type Rep (Document a) Source # | |
Defined in Network.JSONApi.Document type Rep (Document a) = D1 (MetaData "Document" "Network.JSONApi.Document" "json-api-lib-0.1.1.1-Hn5ub1A05S41aavcUBD9m0" False) (C1 (MetaCons "Document" PrefixI True) ((S1 (MetaSel (Just "_data") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ResourceData a)) :*: S1 (MetaSel (Just "_links") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Links))) :*: (S1 (MetaSel (Just "_meta") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Meta)) :*: S1 (MetaSel (Just "_included") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Value])))) |
data ResourceData a Source #
The Resource
type encapsulates the underlying Resource
Included in the top-level Document
, the Resource
may be either
a singleton resource or a list.
For more information see: http://jsonapi.org/format/#document-top-level
Instances
data ErrorDocument a Source #
The ErrorDocument
type represents the alternative form of the top-level
JSON-API requirement.
error
attribute - a descriptive object encapsulating application-specific
error detail.
For more information see: http://jsonapi.org/format/#errors
ErrorDocument | |
|
Instances
The Included
type is an abstraction used to constrain the included
section of the Document to JSON serializable Resource objects while
enabling a heterogeneous list of Resource types.
No data constructors for this type are exported as we need to
constrain the Value
to a heterogeneous list of Resource types.
See mkIncludedResource
for creating Included
types.
Type for providing application-specific detail to unsuccessful API responses.
Specification: http://jsonapi.org/format/#error-objects
Instances
data Relationship Source #
A type representing the Relationship between 2 entities
A Relationship provides basic information for fetching further information about a related resource.
Specification: http://jsonapi.org/format/#document-resource-object-relationships
Instances
Type representing a JSON-API resource object.
A Resource supplies standardized data and metadata about a resource.
Specification: http://jsonapi.org/format/#document-resource-objects
Resource | |
|
Instances
data Relationships Source #
Instances
class (ToJSON a, FromJSON a) => ResourcefulEntity a where Source #
A typeclass for decorating an entity with JSON API properties
resourceIdentifier :: a -> Text Source #
resourceType :: a -> Text Source #
resourceLinks :: a -> Maybe Links Source #
resourceMetaData :: a -> Maybe Meta Source #
resourceRelationships :: a -> Maybe Relationships Source #
fromResource :: Resource a -> a Source #
toResource :: a -> Resource a Source #
class HasIdentifier a where Source #
Typeclass indicating how to access an Identifier
for
a given datatype
identifier :: a -> Identifier Source #
Instances
HasIdentifier (Resource a) Source # | |
Defined in Network.JSONApi.Resource identifier :: Resource a -> Identifier Source # |
data Identifier Source #
Identifiers are used to encapsulate the minimum amount of information to uniquely identify a resource.
This object will be found at multiple levels of the JSON-API structure
Specification: http://jsonapi.org/format/#document-resource-identifier-objects
Instances
Eq Identifier Source # | |
Defined in Network.JSONApi.Identifier (==) :: Identifier -> Identifier -> Bool # (/=) :: Identifier -> Identifier -> Bool # | |
Show Identifier Source # | |
Defined in Network.JSONApi.Identifier showsPrec :: Int -> Identifier -> ShowS # show :: Identifier -> String # showList :: [Identifier] -> ShowS # | |
ToJSON Identifier Source # | |
Defined in Network.JSONApi.Identifier toJSON :: Identifier -> Value # toEncoding :: Identifier -> Encoding # toJSONList :: [Identifier] -> Value # toEncodingList :: [Identifier] -> Encoding # | |
FromJSON Identifier Source # | |
Defined in Network.JSONApi.Identifier parseJSON :: Value -> Parser Identifier # parseJSONList :: Value -> Parser [Identifier] # |
Type representing a JSON-API link object.
Links are an abstraction around an underlying Map consisting of relevance identifiers as keys and URIs as values.
Example JSON:
"links": {
"self": "http://example.com/posts/1"
}
Specification: http://jsonapi.org/format/#document-links
Type representing a JSON-API meta object.
Meta is an abstraction around an underlying Map consisting of resource-specific metadata.
Example JSON:
"meta": {
"copyright": "Copyright 2015 Example Corp.",
"authors": [
"Andre Dawson",
"Kirby Puckett",
"Don Mattingly",
"Ozzie Guillen"
]
}
Specification: http://jsonapi.org/format/#document-meta
class ToJSON a => MetaObject a where Source #
Convienience class for constructing a Meta type
Example usage: @ data Pagination = Pagination { currentPage :: Int , totalPages :: Int } deriving (Show, Generic)
instance ToJSON Pagination instance MetaObject Pagination where typeName _ = "pagination" @
Instances
MetaObject Pagination Source # | Pagination can be used as a meta object if required in addition to the links generated for paging. |
Defined in Network.JSONApi.Pagination typeName :: Pagination -> Text Source # |
data Pagination Source #
Wrapper type for the various components of pagination being page size, page number and the number of resources in total.
Instances
ToJSON Pagination Source # | |
Defined in Network.JSONApi.Pagination toJSON :: Pagination -> Value # toEncoding :: Pagination -> Encoding # toJSONList :: [Pagination] -> Value # toEncodingList :: [Pagination] -> Encoding # | |
MetaObject Pagination Source # | Pagination can be used as a meta object if required in addition to the links generated for paging. |
Defined in Network.JSONApi.Pagination typeName :: Pagination -> Text Source # |
PageNum | |
|
We can specify limits on the number of rows we would like back from the database
newtype ResourceCount Source #
Instances
Show ResourceCount Source # | |
Defined in Network.JSONApi.Pagination showsPrec :: Int -> ResourceCount -> ShowS # show :: ResourceCount -> String # showList :: [ResourceCount] -> ShowS # |
indexLinks :: Text -> Pagination -> Links Source #
Helper function to beuild relative links for a collection of resources of type ResourceEntity.
This helper function assumes that the first page is always page 0.
mkRelationship :: Maybe Identifier -> Maybe Links -> Maybe Relationship Source #
Constructor function for creating a Relationship record
A relationship must contain either an Identifier or a Links record
showLink :: ResourcefulEntity e => e -> Links Source #
Helper function to build relative links for a single resource of type ResourceEntity
mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Document a Source #
Constructor function for the Document data type.
See mkCompoundDocument
for constructing compound Document
including 'side-loaded' resources
mkDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Document a Source #
singleton :: ResourcefulEntity a => a -> ResourceData a Source #
list :: ResourcefulEntity a => [a] -> ResourceData a Source #
mkCompoundDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> Included -> Document a Source #
Constructor function for the Document data type.
See mkIncludedResource
for constructing the Included
type.
Supports building compound documents http://jsonapi.org/format/#document-compound-documents
mkCompoundDocument' :: ResourceData a -> Maybe Links -> Maybe Meta -> Included -> Document a Source #
mkIncludedResource :: ResourcefulEntity a => a -> Included Source #
Constructor function for the Document data type.
Supports building compound documents http://jsonapi.org/format/#document-compound-documents
mkSimpleDocument :: ResourcefulEntity a => [a] -> Document a Source #
A function for document which do not require links or Meta data.
mkSimpleDocument' :: ResourceData a -> Document a Source #
A function for document which do not require links or Meta data.
mkMeta :: MetaObject a => a -> Meta Source #
Convienience constructor function for the Meta type
Useful on its own or in combination with Meta's monoid instance
Example usage: See MetaSpec.hs for an example