Expand description
§Introduction
Ciboulette is a JSON:API library.
It allows one to parse request and build response respecting the JSON:API
specifications.
It aims to have a low memory footprint and be fast.
§High level view of components
At a high level, an API is constitued of resource types. The resource type are organized
in a graph representing their relationships as edges.
In addition to the graph, an adgacent map is used to efficiently retrieve resource types by their alias. This whole structure is held in a store.
§Resource types
The resource types can be built using a resource type builder. It’s made of :
- A name, that will later be used as an alias to fetch the resource types from the store’s graph.
- A id type, which will be used to deserialize the ids the requests.
- A schema which will be used to deserialize the body of the requests and serialize the response.
§Relationship options
§Many-to-Many
The option struct map a resource “A” to another resource “C” through another resource “B” (bucket)
Resource A Resource B (bucket) Resource C
┌─────────────────┐ ┌─────────────────────────────────────────────┐ ┌─────────────────┐
│ │ │ │ │ │
│ peoples──►id───┼──┼──►people_id◄──people-article──►article_id◄──┼──┼──id◄──articles │
│ │ │ │ │ │
└─────────────────┘ └─────────────────────────────────────────────┘ └─────────────────┘When creating a Many-to-Many relationships (A <-> C), we’ll also create a Many-to-One relationship between the table
A -> B, C -> B, B -> A and B -> C so that we can reference the relationship directly.
§One-to-Many / Many-to-One
The option struct map a “many” resource to a “one” resource.
Many table One table
┌──────────────────────────────────────────────────┐ ┌──────────────────────────────────────┐
│ │ │ │
│ many_table_element_0──────────►many_table_key_0──┼──┼──►one_table_id◄───one_table_element │
│ │ │ ▲ ▲ │
│ │ │ │ │ │
│ many_table_element_1──────────►many_table_key_1──┼──┼─────┘ │ │
│ │ │ │ │
│ │ │ │ │
│ many_table_element_2──────────►many_table_key_2──┼──┼────────────┘ │
│ │ │ │
│ │ └──────────────────────────────────────┘
└──────────────────────────────────────────────────┘In the option a field is used to determined if a Many-to-One/One-to-Many relationship is part of Many-to-Many relationship.
§Requests
Every requests boils down to the same components. But there is some quirks :
- Creation request can be valid without resource id,
- Update request can have a body of resource identifier.
Every requests must first be deserialized using the request builder. Then it can be built into an generic request. From that, one can convert to the desired request type depending on the intention. Trying to convert a generic request to an incompatible sub-type will result in an error. The correct conversion map goes like this :
| Intention | Request type |
|---|---|
| Create | Create request |
| Read | Read request |
| Update | Update request |
| Delete | Delete request |
Every sub-type of requests implement a common trait to allow for genericity.
§Responses
A response is built from a request and a list of response element.
Depending on the request, the response will be built to the correct format.
§Response elements
Each response should have a single main resource type.
The response elements are composed as follow for an element part of the main resource type:
| Response element field | Always required | Description |
|---|---|---|
type | ✅ | The current element resource type |
identifier | ✅ | The current element resource identifier |
data | ❌ | The JSON data of the resource, if any |
related.rel_chain | ❌ (only for related data) | Chain of relation metadata from the main resource type |
related.element | ❌ (only for related data) | The resource identifier of the element it relates to |
Structs§
- Ciboulette
Body - A
json:apidocument object - Ciboulette
Body Builder - Builder object for CibouletteBody
- Ciboulette
Body Link - A
json:apitop-level link object with pagination support - Ciboulette
Body Pagination - A
json:apitop-level link object with pagination support - Ciboulette
Config - Ciboulette configuration
- Ciboulette
Create Request - A
POSTrequest - Ciboulette
Delete Request - A
DELETErequest - Ciboulette
Error Link - A link describing a
json:apierror - Ciboulette
Error Obj - Object of a
json:apierror - Ciboulette
Error Request - An outbound response, built from an inbound request.
- Ciboulette
Error Source - Source object of a
json:apierror - Ciboulette
Json ApiVersion - Object holder
json:apiversion - Ciboulette
Link - A
json:apilink object - Ciboulette
Link Obj - A
json:apiinner link object - Ciboulette
Query Parameters - Query parameters for
json:api - Ciboulette
Query Parameters Builder - Builder object for CibouletteQueryParameters
- Ciboulette
Read Request - A ‘GET’ request
- Ciboulette
Relationship Many ToMany Option - Many-to-Many relationships options
- Ciboulette
Relationship Many ToMany Option Builder - Many-to-Many relationships option builder
- Ciboulette
Relationship Object - A
json:apirelationship object - Ciboulette
Relationship Object Builder - Builder for CibouletteRelationshipObject
- Ciboulette
Relationship OneTo Many Option - One-to-Many/Many-to-One relationships options
- Ciboulette
Relationship OneTo Many Option Builder - One-to-Many/Many-to-one relationships option builder
- Ciboulette
Request - Abstract representation of a
JSON:APIrequest - Ciboulette
Request Builder - Builder object for CibouletteBody
- Ciboulette
Resource - A
json:apiresource object - Ciboulette
Resource Builder - Builder object for CibouletterResource
- Ciboulette
Resource Identifier - A
json:apiresource identifier object - Ciboulette
Resource Identifier Builder - Builder for resource identifier
- Ciboulette
Resource Identifier Permissive - A
json:apiresource identifier object - Ciboulette
Resource Relationship Details - Relationships metadata for CibouletteResourceType
- Ciboulette
Resource Response Identifier - A
json:apiresource identifier object - Ciboulette
Resource Response Identifier Builder - Builder for CibouletteResourceResponseIdentifier
- Ciboulette
Resource Type - Describe a
json:apitype attribute schema and list its relationships - Ciboulette
Resource Type Builder - Describe a
json:apitype attribute schema and list its relationships - Ciboulette
Response - A response, built from a request.
- Ciboulette
Response Body JSON:APIresponse body- Ciboulette
Response Data Builder - A builder structure for CibouletteOutboundRequest
- Ciboulette
Response Element - Container for response element.
- Ciboulette
Response Relationship Object - Relationships object included in a response
- Ciboulette
Response Resource - Resource included in a response
- Ciboulette
Sorting Element - Element of a sorting list.
- Ciboulette
Store - Map of accepted resource types
- Ciboulette
Store Builder - Builder for CibouletteStore
- Ciboulette
Update Relationship Body - Body of a relationships update request
- Ciboulette
Update Request - An
UPDATErequest
Enums§
- Ciboulette
Clash Direction - When describing KeyClash, we need to know if the field was supposed be with or without another field
- Ciboulette
Error - An error throwable by Ciboulette
- Ciboulette
Id - Resource id type
- Ciboulette
IdSelector - Resource id type selector
- Ciboulette
IdType - Type of resource id
- Ciboulette
IdType Selector - Type of resource id
- Ciboulette
Intention - Represent the client intention (request method) when sending the request
- Ciboulette
Optional Data - Wrapper for optional data
- Ciboulette
Page Type - The page type used in the CibouletteQueryParametersField
- Ciboulette
Path - Path of a
JSON:APIrequest - Ciboulette
Path Builder - Path builder for
JSON:APIrequests - Ciboulette
Path Type JSON:APIPath type- Ciboulette
Relationship Option - Relationships options
- Ciboulette
Relationship Option Builder - Relationship options builder
- Ciboulette
Request Selector - Builder object for CibouletterResourceSelector
- Ciboulette
Resource Identifier Selector - A selector between a single or multiple
json:apiresource identifier objects - Ciboulette
Resource Identifier Selector Builder - A selector for resource identifier, to either select one or many resource identifiers
- Ciboulette
Resource Response Identifier Selector - A selector between a single or multiple
json:apiresource identifier objects - Ciboulette
Resource Response Identifier Selector Builder - Selector for CibouletteResourceResponseIdentifierSelectorBuilder
- Ciboulette
Resource Selector - A selector between a single or multiple
json:apiresource objects - Ciboulette
Resource Selector Builder - Builder object for CibouletterResourceSelector
- Ciboulette
Response Quantity - The quantity of data that should be returned
- Ciboulette
Response Required Type - The format the return object should have
- Ciboulette
Response Resource Selector - Selector for CibouletteResponseResource
- Ciboulette
Response Status - The status a response should send
- Ciboulette
Sorting Direction - Direction for sorting element
- Ciboulette
Update Request Type - Update request type
Traits§
- Ciboulette
Request Commons JSON:APIinbound requests