Safe Haskell | None |
---|---|
Language | Haskell2010 |
Entry-point module for this package.
Contains representations of the top-level JSON-API document structure.
- data Document a
- data ErrorDocument a = ErrorDocument {
- _error :: Error a
- _errorLinks :: Maybe Links
- _errorMeta :: Maybe Meta
- data Error a = Error {}
- data ResourceData a
- data Relationship
- data Resource a = Resource {
- getIdentifier :: Identifier
- getResource :: a
- getLinks :: Maybe Links
- getMetaData :: Maybe Meta
- getRelationships :: Maybe (Map Text Relationship)
- class (ToJSON a, FromJSON a) => ResourcefulEntity a where
- data Identifier = Identifier {}
- data Links
- data Meta = Meta Object
- class ToJSON a => MetaObject a where
- toLinks :: [(Rel, URL)] -> Links
- mkRelationship :: Maybe Identifier -> Maybe Links -> Maybe Relationship
- mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> [Value] -> 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
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 | |
|
Eq (ErrorDocument a) Source # | |
Show (ErrorDocument a) Source # | |
Generic (ErrorDocument a) Source # | |
ToJSON a => ToJSON (ErrorDocument a) Source # | |
FromJSON a => FromJSON (ErrorDocument a) Source # | |
type Rep (ErrorDocument a) Source # | |
Type for providing application-specific detail to unsuccessful API responses.
Specification: http://jsonapi.org/format/#error-objects
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
Eq a => Eq (ResourceData a) Source # | |
Show a => Show (ResourceData a) Source # | |
Generic (ResourceData a) Source # | |
ToJSON a => ToJSON (ResourceData a) Source # | |
FromJSON a => FromJSON (ResourceData a) Source # | |
type Rep (ResourceData a) Source # | |
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
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 | |
|
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 (Map Text Relationship) Source #
fromResource :: Resource a -> a Source #
toResource :: a -> Resource a 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
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" @
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
mkDocument :: ResourcefulEntity a => [a] -> Maybe Links -> Maybe Meta -> [Value] -> Document a Source #
Constructor function for the Document data type.
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