Minim API Description Namespace
npm install minim-api-description

This library provides an interface to the Refract API Description namespace.
It extends upon the base types as defined in Minim.
``sh`
npm install minim-api-description
`js
import minim from 'minim';
import apiDescription from 'minim-api-description';
const namespace = minim.namespace()
.use(apiDescription);
// Initialize elements directly
const Category = namespace.getElementClass('category');
let category = new Category();
`
#### Properties
##### category.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = category.copy;
##### category.dataStructures
Get an array element of all child elements with the element name category and a class name dataStructures. This property is read-only.
`js`
let dataStructures = category.dataStructures;
##### category.resources
Get an array element of all child elements with the element name resource. This property is read-only.
`js`
let resources = category.resources;
##### category.resourceGroups
Get an array element of all child elements with the element name category and a class name resourceGroup. This property is read-only.
`js`
let groups = category.resourceGroups;
##### category.scenarios
Get an array element of all child elements with a class name scenario. This property is read-only.
`js`
let scenarios = category.scenarios;
##### category.transitions
Get an array element of all child elements with the element name transition. This property is read-only.
`js`
let transitions = category.transitions;
##### category.transitionGroups
Get an array element of all child elements with the element name category and a class name transitions. This property is read-only.
`js`
let groups = category.transitionGroups;
##### category.authSchemes
Get an array element of all child element with element name equal to one of the names given below. This property is read-only.
* Basic Authentication Scheme
* Token Authentication Scheme
* OAuth2 Scheme
`js`
let schemes = category.authSchemes;
##### category.authSchemeGroups
Get an array element of all child elements with the element name category and a class name authSchemes. This property is read-only.
`js`
let groups = category.authSchemeGroups;
`jsDescription: ${copy.toValue()}
console.log();`
#### Properties
##### copy.contentType
The optional content-type of the element's content.
`js
// Get the content-type
console.log(copy.contentType.toValue());
// Set the content-type
copy.contentType = 'text/markdown';
`
#### Properties
##### scheme.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = scheme.copy;
##### scheme.transitions
Get an array element of all child elements with the element name transition. This property is read-only.
`jsTransition: ${transition.title}
for (const transition of scheme.transitions) {
console.log();`
}
##### scheme.members
Get an array element of all child elements with the element name member. This property is read-only.
`jsMember: ${member.key}
for (const member of scheme.members) {
console.log()`
}
#### Properties
##### resource.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = resource.copy;
##### resource.href
The URL template of this resource.
`jsURL: ${resource.href.toValue()}
// Get the href
console.log();
// Set the href
resource.href = '/foo/{id}';
`
##### resource.hrefVariables
The description of any variables present in the resource.href URL template.
`js
// Get the href variables
console.log(resource.hrefVariables.keys());
// Set the href variables
resource.hrefVariables = {
id: 'foo'
}
`
##### resource.transitions
Get an array element of all child elements with the element name transition. This property is read-only.
`jsTransition: ${transition.title.toValue()}
for (const transition of resource.transitions) {
console.log();`
}
##### resource.dataStructure
Get the first child element with the element name dataStructure. This property is read-only.
`js`
console.log(resource.dataStructure.keys());
#### Properties
##### transition.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = transition.copy;
##### transition.method
Get the HTTP method of the transition, if there is one, by finding the first HTTP request and inspecting its method. This property is read-only.
`js`
let method = transition.method.toValue();
##### transition.relation
Defines a relationship to another resource or transition. Useful for hypermedia.
`jsRelation: ${transition.relation.toValue()}
// Get the relation
console.log();
// Set the relation
transition.relation = '...';
`
##### transition.href
Overrides the resources URL template with one specific to this transition.
`jsURL: ${transition.href.toValue()}
// Get the href
console.log();
// Set the href
transition.href = '/foo/{id}';
`
##### transition.computedHref
Gets either the transition's href or the first transaction's request's href if it exists, otherwise returns null. This property is read-only.
`jsURL: ${transition.computedHref.toValue()}
console.log();`
##### transition.hrefVariables
The description of any variables present in the transition.href URL template.
`js
// Get the href variables
console.log(transition.hrefVariables.keys());
// Set the href variables
transition.hrefVariables = {
id: 'foo'
}
`
##### transition.data
The data structure describing the body payload for this transition.
`js
// Get the data attributes
console.log(transition.data.toRefract());
// Set the data attributes
transition.data = minim.toElement({one: 1});
`
##### transition.contentTypes
A list of content types supported by the transition.
`js
// Get the content types
console.log(transition.contentTypes);
// Set the content types
transition.contentTypes = [
'application/json',
'application/yaml'
]
`
##### transition.transactions
An array element of HTTP transaction elements. This property is read-only.
`js${transaction.request.method}
// Print out each transaction's HTTP request method
for (const transaction of transition.transactions) {
console.log();`
}
#### Properties
##### transaction.request
The HTTP request component of this transaction. It returns an HttpRequest element if one has been defined. This property is read-only.
`js`
// Get the HTTP request
let request = transaction.request;
##### transaction.response
The HTTP response component of this transaction. It returns an HttpResponse element if one has been defined. This property is read-only.
`js`
// Get the HTTP response
let response = transaction.response;
##### transaction.authSchemes
It returns an array of elements derived from AuthScheme elements. This property is read-only.
`js`
let schemes = transaction.authSchemes;
#### Properties
##### request.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = request.copy;
##### request.method
The HTTP method of this request, e.g. GET or POST.
`jsHTTP method: ${request.method.toValue()}
// Get the HTTP method
console.log();
// Set the HTTP method
request.method = 'PUT';
`
##### request.href
Overrides the resources URL template with one specific to this request.
`jsURL: ${request.href.toValue()}
// Get the href
console.log();
// Set the href
request.href = '/foo/{id}';
`
##### request.headers
The HTTP headers for this request. See also the request.header(name) shortcut, which will get the values for a header by name.
`js
// Get the headers element
let headers = request.headers;
// Set the headers element
request.headers = new HttpHeaders();
`
##### request.contentType
The computed content type of this request, either from a Content-Type header or from the message content. This property is read-only.
`js${request.contentType}
// Get the content type
console.log();`
##### request.dataStructure
The request body data structure, if it exists. This property is read-only.
`js`
let data = request.dataStructure;
##### request.messageBody
The request body content, if it exists. This property is read-only.
`jsBody: ${request.messageBody}
// Print out the body content as a string
console.log();`
##### request.messageBodySchema
The request body schema, if it exists. This property is read-only.
`jsSchema: ${request.messageBodySchema}
// Print out the body schema as a string
console.log();`
#### Methods
##### request.header(name)
Get a case-insensitive header by name. This returns a list of strings, because headers can be defined multiple times.
`js`
// Get the content type header
let type = request.header('Content-Type')[0].toValue();
#### Properties
##### response.copy
Get an array element of all child elements with the element name copy. This property is read-only.
`js`
let copy = response.copy;
##### response.statusCode
The HTTP status code, e.g. 200 or 404.
`jsCode: ${response.statusCode.toValue()}
// Get the status code
console.log();
// Set the status code
response.statusCode = 400;
`
##### response.headers
The HTTP headers for this response. See also the response.header(name) shortcut, which will get the values for a header by name.
`js
// Get the headers element
let headers = response.headers;
// Set the headers element
response.headers = new HttpHeaders();
`
##### response.contentType
The computed content type of this response, either from a Content-Type header or from the message content. This property is read-only.
`js${response.contentType.toValue()}
// Get the content type
console.log();`
##### response.dataStructure
The response body data structure, if it exists. This property is read-only.
`js`
let data = response.dataStructure;
##### response.messageBody
The response body content, if it exists. This property is read-only.
`jsBody: ${response.messageBody}
// Print out the body content as a string
console.log();`
##### response.messageBodySchema
The response body schema, if it exists. This property is read-only.
`jsSchema: ${response.messageBodySchema}
// Print out the body schema as a string
console.log();`
#### Methods
##### response.header(name)
Get a case-insensitive header by name. This returns a list of strings, because headers can be defined multiple times.
`js`
// Get the content type header
let type = response.header('Content-Type')[0];
#### Properties
##### asset.contentType
The content type of this asset, e.g. application/json.
`jsType: ${asset.contentType.toValue()}
// Get the content type
console.log();
// Set the content type
asset.contentType = 'application/yaml';
`
##### asset.href
A link to this asset.
`jsLocation: ${asset.href.toValue()}
// Get the link
console.log();
// Set the link
asset.href = '/path/to/asset'
`
#### Methods
##### headers.include(name)
Return a filtered array element of headers with the given case-insensitive name. Each header is a member element where the key is the header name and the value is the header value.
`js`
let accept = headers.include('Accept');
##### headers.exclude(name)
Return a filtered array element of headers without the given case-insensitive name. Each header is a member element where the key is the header name and the value is the header value.
`js`
let filtered = headers.exclude('Content-Type');
This element represents the API Elements extensions element.
#### Properties
##### profile
Gets the extension elements profile href. This property is read-only.
`js``
let profile = extension.profile.toValue();