Minim API Description Namespace
This library provides an interface to the Refract API Description namespace.
It extends upon the base types as defined in Minim.
Install
npm install minim-api-description
Usage Example
;; const namespace = minim ; // Initialize elements directlyconst Category = namespace;let category = ;
Element Reference
ArrayElement)
Category (A grouping element to hold other elements.
Properties
category.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = categorycopy;
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.
let dataStructures = categorydataStructures;
category.resources
Get an array element of all child elements with the element name resource
. This property is read-only.
let resources = categoryresources;
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.
let groups = categoryresourceGroups;
category.scenarios
Get an array element of all child elements with a class name scenario
. This property is read-only.
let scenarios = categoryscenarios;
category.transitions
Get an array element of all child elements with the element name transition
. This property is read-only.
let transitions = categorytransitions;
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.
let groups = categorytransitionGroups;
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
let schemes = categoryauthSchemes;
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.
let groups = categoryauthSchemeGroups;
StringElement)
Copy (An element that contains copy text used to describe elements in the API Description namespace. The element's content contains the text:
console;
Properties
copy.contentType
The optional content-type of the element's content.
// Get the content-typeconsole; // Set the content-typecopycontentType = 'text/markdown';
Array Element)
AuthScheme (This element describes an auth scheme.
Properties
scheme.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = schemecopy;
scheme.transitions
Get an array element of all child elements with the element name transition
. This property is read-only.
for const transition of schemetransitions console;
scheme.members
Get an array element of all child elements with the element name member
. This property is read-only.
for const member of schememembers console
DataStructure (Element)
This element describes a data structure.
ArrayElement)
Resource (Properties
resource.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = resourcecopy;
resource.href
The URL template of this resource.
// Get the hrefconsole; // Set the hrefresourcehref = '/foo/{id}';
resource.hrefVariables
The description of any variables present in the resource.href
URL template.
// Get the href variablesconsole; // Set the href variablesresourcehrefVariables = id: 'foo'
resource.transitions
Get an array element of all child elements with the element name transition
. This property is read-only.
for const transition of resourcetransitions console;
resource.dataStructure
Get the first child element with the element name dataStructure
. This property is read-only.
console;
ArrayElement)
Transition (This element represents a resource transition.
Properties
transition.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = transitioncopy;
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.
let method = transitionmethod;
transition.relation
Defines a relationship to another resource or transition. Useful for hypermedia.
// Get the relationconsole; // Set the relationtransitionrelation = '...';
transition.href
Overrides the resources URL template with one specific to this transition.
// Get the hrefconsole; // Set the hreftransitionhref = '/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.
console;
transition.hrefVariables
The description of any variables present in the transition.href
URL template.
// Get the href variablesconsole; // Set the href variablestransitionhrefVariables = id: 'foo'
transition.data
The data structure describing the body payload for this transition.
// Get the data attributesconsole; // Set the data attributestransitiondata = minim;
transition.contentTypes
A list of content types supported by the transition.
// Get the content typesconsole; // Set the content typestransitioncontentTypes = 'application/json' 'application/yaml'
transition.transactions
An array element of HTTP transaction elements. This property is read-only.
// Print out each transaction's HTTP request methodfor const transaction of transitiontransactions console;
ArrayElement)
HttpTransaction (This element represents an HTTP transaction.
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.
// Get the HTTP requestlet request = transactionrequest;
transaction.response
The HTTP response component of this transaction. It returns an HttpResponse element if one has been defined. This property is read-only.
// Get the HTTP responselet response = transactionresponse;
transaction.authSchemes
It returns an array of elements derived from AuthScheme elements. This property is read-only.
let schemes = transactionauthSchemes;
ArrayElement)
HttpRequest (This element represents an HTTP request.
Properties
request.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = requestcopy;
request.method
The HTTP method of this request, e.g. GET
or POST
.
// Get the HTTP methodconsole; // Set the HTTP methodrequestmethod = 'PUT';
request.href
Overrides the resources URL template with one specific to this request.
// Get the hrefconsole; // Set the hrefrequesthref = '/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.
// Get the headers elementlet headers = requestheaders; // Set the headers elementrequestheaders = ;
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.
// Get the content typeconsole;
request.dataStructure
The request body data structure, if it exists. This property is read-only.
let data = requestdataStructure;
request.messageBody
The request body content, if it exists. This property is read-only.
// Print out the body content as a stringconsole;
request.messageBodySchema
The request body schema, if it exists. This property is read-only.
// Print out the body schema as a stringconsole;
Methods
request.header(name)
Get a case-insensitive header by name. This returns a list of strings, because headers can be defined multiple times.
// Get the content type headerlet type = request0;
ArrayElement)
HttpResponse (This element represents an HTTP response.
Properties
response.copy
Get an array element of all child elements with the element name copy
. This property is read-only.
let copy = responsecopy;
response.statusCode
The HTTP status code, e.g. 200
or 404
.
// Get the status codeconsole; // Set the status coderesponsestatusCode = 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.
// Get the headers elementlet headers = responseheaders; // Set the headers elementresponseheaders = ;
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.
// Get the content typeconsole;
response.dataStructure
The response body data structure, if it exists. This property is read-only.
let data = responsedataStructure;
response.messageBody
The response body content, if it exists. This property is read-only.
// Print out the body content as a stringconsole;
response.messageBodySchema
The response body schema, if it exists. This property is read-only.
// Print out the body schema as a stringconsole;
Methods
response.header(name)
Get a case-insensitive header by name. This returns a list of strings, because headers can be defined multiple times.
// Get the content type headerlet type = response0;
Asset (Element)
This element represents an HTTP message payload or schema asset.
Properties
asset.contentType
The content type of this asset, e.g. application/json
.
// Get the content typeconsole; // Set the content typeassetcontentType = 'application/yaml';
asset.href
A link to this asset.
// Get the linkconsole; // Set the linkassethref = '/path/to/asset'
ObjectElement)
HrefVariables (This element represents a set of URI template variables.
ArrayElement)
HttpHeaders (This element represents a set of HTTP headers.
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.
let accept = headers;
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.
let filtered = headers;
Extension (Element)
This element represents the API Elements extensions element.
Properties
profile
Gets the extension elements profile href. This property is read-only.
let profile = extensionprofile;