New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource Namespace #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,328 @@ | ||
# Resource Namespace | ||
|
||
This document extends [Refract][] [MSON Namespace][] to define REST Resource data structure elements. | ||
|
||
## Content | ||
|
||
<!-- TOC depth:3 withLinks:1 updateOnSave:0 --> | ||
- [Resource Namespace](#resource-namespace) | ||
- [Content](#content) | ||
- [About this Document](#about-this-document) | ||
- [Supporting Data Types](#supporting-data-types) | ||
- [Href (string)](#href-string) | ||
- [Templated Href (string)](#templated-href-string) | ||
- [Href Variables (Object Type)](#href-variables-object-type) | ||
- [Data Structure (MSON Element)](#data-structure-mson-element) | ||
- [Asset (Element)](#asset-element) | ||
- [Resource Elements](#resource-elements) | ||
- [Resource (Element)](#resource-element) | ||
- [Transition (Element)](#transition-element) | ||
- [Protocol-specific Elements](#protocol-specific-elements) | ||
- [HTTP Transaction (Element)](#http-transaction-element) | ||
- [HTTP Headers (Array Type)](#http-headers-array-type) | ||
- [HTTP Message Payload (Element)](#http-message-payload-element) | ||
- [HTTP Request Message (HTTP Message Payload)](#http-request-message-http-message-payload) | ||
- [HTTP Response Message (HTTP Message Payload)](#http-response-message-http-message-payload) | ||
|
||
<!-- /TOC --> | ||
|
||
## About this Document | ||
|
||
This document conforms to [RFC 2119][], which says: | ||
|
||
> The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. | ||
|
||
[MSON][] is used throughout this document. | ||
|
||
## Supporting Data Types | ||
|
||
### Href (string) | ||
|
||
The value of the `Href` type SHOULD be resolved as a URI-Reference per [RFC 3986][] and MAY be a relative reference to a URI. | ||
The value of the `Href` type MUST NOT be a URI Template. | ||
|
||
### Templated Href (string) | ||
|
||
The value of `Templated Href` type is to be used as a URI Template, as defined in [RFC 6570][]. | ||
The value of the `Templated Href` type is a template used to determine the target URI of the related resource or transition. | ||
The value of the `Templated Href` type SHOULD be resolved as a URI-Reference per [RFC 3986][] and MAY be a relative reference to a URI. | ||
|
||
### Href Variables (Object Type) | ||
|
||
The definition is a MSON namespace `Object Type` where keys are respective URI Template variables. | ||
|
||
#### Properties | ||
|
||
- `element`: hrefVariables (string, fixed) | ||
|
||
### Data Structure (MSON Element) | ||
|
||
Data structure definition using MSON namespace elements. | ||
|
||
#### Properties | ||
|
||
- `element`: dataStructure (string, fixed) | ||
|
||
### Asset (Element) | ||
|
||
Arbitrary data asset. | ||
|
||
#### Properties | ||
|
||
- `element`: asset (string, fixed) | ||
- `meta` | ||
- `class` (array, fixed) | ||
- (enum[string]) | ||
- messageBody - Asset is an example of message-body | ||
- messageBodySchema - Asset is an schema for message-body | ||
- `attributes` (object) | ||
- `contentType` (string) - Optional media type of the asset | ||
- `href` (Href) - Link to the asset | ||
- `content` (string) - A textual representation of the asset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing trailing full stop on a few of the properties such as the above. Only pointing out because some have a full-stop and it's inconsistent. But not really a blocking problem.
|
||
|
||
## Resource Elements | ||
|
||
### Resource (Element) | ||
|
||
The Resource representation with its available transitions and attributes. | ||
|
||
#### Properties | ||
|
||
- `element`: resource (string, fixed) | ||
- `attributes` (object) | ||
- `href` (Templated Href) - URI Template of this resource. | ||
- `hrefVariables` (Href Variables) - Definition of URI Template variables used in the `href` property. | ||
- `content` (array) | ||
- (Transition) - State transition available for this resource. | ||
|
||
The `content` MAY include multiple `Transition` elements. | ||
|
||
- (Data Structure) - Data structure representing the resource. | ||
|
||
The `content` MUST NOT include more than one `Data Structure`. | ||
|
||
#### Example | ||
|
||
```json | ||
{ | ||
"element": "resource", | ||
"meta": { | ||
"title": "Question", | ||
"description": "A Question object has the following attributes." | ||
}, | ||
"attributes": { | ||
"href": "/questions/{question_id}", | ||
"hrefVariables": { | ||
"element": "hrefVariables", | ||
"attributes": { | ||
"name": "question_id" | ||
}, | ||
"content": null | ||
} | ||
}, | ||
"content": [ | ||
{ | ||
"element": "dataStructure" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Transition (Element) | ||
|
||
A transition is an available progression from one state to another state. | ||
Exercising a transition initiates a transaction. | ||
|
||
The content of this element is array of protocol-specific transactions. | ||
|
||
Note: At the moment only the HTTP protocol is supported. | ||
|
||
#### Properties | ||
|
||
- `element`: transition (string, fixed) | ||
- `attributes` (object) | ||
- `relation` - (string) - Link relation type as specified in [RFC 5988][]. | ||
|
||
The value of `relation` attribute SHOULD be interpreted as a link relation | ||
between transition's parent resource and the transition's target resource | ||
as specified in the `href` attribute. | ||
|
||
- `href` (Templated Href) - The URI template for this transition. | ||
|
||
If present, the value of the `href` attribute SHOULD be used to resolve | ||
target URI of the transition. | ||
|
||
If not set, the parent `resource` element `href` attribute SHOULD be | ||
used to resolve the target URI of the transition. | ||
|
||
- `parameters` (Href Variables) - Input parameters. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semantically, the two are different. Let's start with transition: Any transition may have input properties (refer to representor charter) those properties are either parameters or attributes. In addition to that – since a templated href can be provided – you can have some other variables in there. Consider resource "friends" which is an array of friend resources every user have. Its templated href may be something like You can see that Now, strictly speaking, the parameter of the So in theory the transition should have both Does this make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I guess we should wait and see for adding the |
||
|
||
Definition of any input URI path segments or URI query parameters for this transition. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thought of this. Would it help to clarify that if the |
||
|
||
If `href` and `parameters` attributes aren't set, the parent `resource` | ||
element `hrefVariables` SHOULD be used to resolve the transition input | ||
parameters. | ||
|
||
- `attributes` (Data Structure) - Input attributes. | ||
|
||
Definition of any input message-body attribute for this transition. | ||
|
||
- `content` (array[HTTP Transaction]) - Array of transaction examples. | ||
|
||
Transaction examples are protocol-specific examples of REST transaction | ||
that was initialized by exercising a transition. | ||
|
||
For the time being this namespace defines only HTTP-specific transaction | ||
data structures. | ||
|
||
#### Example | ||
|
||
```json | ||
{ | ||
"element": "transition", | ||
"attributes": { | ||
"relation": "update", | ||
"href": "https://polls.apiblueprint.org/questions/{question_id}" | ||
}, | ||
"content": null | ||
} | ||
``` | ||
|
||
## Protocol-specific Elements | ||
|
||
### HTTP Transaction (Element) | ||
|
||
Example of an HTTP Transaction. The example's content consist of a request-response | ||
message pair. A transaction example MUST contain exactly one HTTP request and one HTTP response message. | ||
|
||
#### Properties | ||
|
||
- `element`: httpTransaction (string, fixed) | ||
- `content` (array, fixed) - Request response message pair (tuple). | ||
|
||
The array MUST contain exactly two elements. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MSON thought: Something for defining array lengths in MSON might be useful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smizell yup, I guess this is for the upcoming release and "validations' |
||
|
||
- Elements | ||
- (HTTP Request Message) | ||
- (HTTP Response Message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I was pressing comment, I noticed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yup. That "fixes" the content of the property. |
||
|
||
#### Example | ||
|
||
```json | ||
{ | ||
"element": "httpTransaction", | ||
"content": [ | ||
{ | ||
"element": "httpRequest", | ||
"attributes": { | ||
"method": "GET", | ||
"href": "https://polls.apiblueprint.org/questions/1" | ||
}, | ||
"content": null | ||
}, | ||
{ | ||
"element": "httpResponse", | ||
"attributes": { | ||
"status": 200, | ||
"assets": [ | ||
{ | ||
"element": "asset", | ||
"meta": { | ||
"class": "messageBody" | ||
}, | ||
"attributes": {}, | ||
"content": "{\"name\": \"John\"}" | ||
} | ||
] | ||
}, | ||
"content": null | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### HTTP Headers (Array Type) | ||
|
||
Ordered array of HTTP header-fields. | ||
|
||
The `name` meta attribute value of every element in the `content` SHOULD be | ||
interpreted as HTTP header field-name as defined in [RFC 7230][]. | ||
|
||
#### Properties | ||
|
||
- `element`: `httpHeaders` | ||
- `content` (array) | ||
- (Element) | ||
- `meta` | ||
- `name` (string) - HTTP header field-name. | ||
|
||
#### Example | ||
|
||
```json | ||
{ | ||
"element": "httpHeaders", | ||
"content": [ | ||
{ | ||
"element": "string", | ||
"meta": { | ||
"name": "Content-Type" | ||
}, | ||
"content": "application/json" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### HTTP Message Payload (Element) | ||
|
||
Payload of an HTTP message. Its metadata in the form of headers and data in form | ||
of Data structure or assets. | ||
|
||
#### Properties | ||
|
||
- `attributes` | ||
- `headers` (HTTP Headers) | ||
- `content` (array) | ||
- (Data Structure) - Data structure describing the payload. | ||
|
||
The `content` MUST NOT contain more than one `Data Structure`. | ||
|
||
- (Asset) - A data asset associated with the payload's body. | ||
|
||
This asset MAY represent payload body or body's schema. | ||
|
||
The `content` SHOULD NOT contain more than one asset of its respective type. | ||
|
||
### HTTP Request Message (HTTP Message Payload) | ||
|
||
HTTP request message. | ||
|
||
#### Properties | ||
|
||
- `element`: httpRequest (string, fixed) | ||
- `attributes` | ||
- `method` (string) - HTTP request method. | ||
- `href` (Href) - A concrete URI for the request. | ||
|
||
### HTTP Response Message (HTTP Message Payload) | ||
|
||
HTTP response message. | ||
|
||
#### Properties | ||
|
||
- `element`: httpResponse (string, fixed) | ||
- `attributes` | ||
- `statusCode` (number) - HTTP response status code. | ||
|
||
--- | ||
|
||
|
||
[MSON]: https://github.com/apiaryio/mson | ||
[Refract]: ../refract-spec.md | ||
[MSON Namespace]: mson-namespace.md | ||
|
||
[RFC 2119]: https://datatracker.ietf.org/doc/rfc2119/ | ||
[RFC 3986]: https://datatracker.ietf.org/doc/rfc3986/ | ||
[RFC 5988]: http://datatracker.ietf.org/doc/rfc5988/ | ||
[RFC 6570]: https://datatracker.ietf.org/doc/rfc6570/ | ||
[RFC 7230]: http://datatracker.ietf.org/doc/rfc7230/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to be a really cool way of defining inputs.