-
Notifications
You must be signed in to change notification settings - Fork 19
Request
A Request component represents the central element of an HTTP request. It has a few descriptive fields - id, name and description - as well as core elements of an http request, such as the method, the url, the authentication methods, and the parameters used either in the query section, the headers, or in the body of the request. These parameters can be included or discarded based on their compliance with environments, embodied by the field bodies.
the url is naturally represented by a URL object, while the parameters are regrouped in a ParameterContainer, and the environments in an Immutable.List of Body, named bodies.
/* if in src/ */
import { Request } from './models/Core'
Request extends Immutable.Record using the following pattern:
class Request extends Immutable.Record({
id: null,
name: null,
description: null,
url: new URL(),
method: null,
parameters: new ParameterContainer(),
bodies: Immutable.List(),
auths: Immutable.List(),
responses: Immutable.List(),
timeout: null
})
-
Request.id
is a unique identifier for the Request.
-
Request.name
is simple name to identify the request. there are no uniqueness requirements.
-
Request.url
expects aURL
object. Required.
-
Request.description
expects a description of the intent of theRequest
.
-
Request.parameters
expects aParameterContainer
. This ParameterContainer should contain all the possibleParameters
that can be used in this Request.
-
Request.bodies
expects anImmutable.List
ofBody
objects. This List should contain all the possible environments which can be used with theRequest
.
-
Request.auths
expects anImmutable.List
ofAuth
objects. These authentication methods are orthogonal toRequest.bodies
; any authentication defined can be used with any environment defined. A future version will allow for complex interactions between the two lists.
-
Request.responses
expects anImmutable.List
ofResponse
objects, that describe the possible responses of to that Request.
-
Request.timeout
defines the time in seconds after which the Request should time out.
Please note that this example is abstract, and is there purely to represent the different interactions with Request
. The data may be non-sensical.
import parameters from './samples/parameters-examples'
import containers from './samples/containers-examples'
import bodies from './samples/bodies-examples'
import responses from './samples/responses-examples'
import { Request } from './models/Core'
let request = new Request({
id: null,
name: 'Fetch Pet Data'
method: 'GET',
url: new URL({
schemes: [ 'https' ],
host: 'localhost:8080',
path: '/path/to/request'
})
description: 'A simple description of what the Request does',
parameters: containers[0],
bodies: new Immutable.List([ bodies[0], bodies[1]]),
responses: new Immutable.List([ responses[0] ]),
auths: new Immutable.List([ null, new Auth.Basic() ])
})
request = request
.set('id', '27:a3:a0:6f:1f:d6')
.set('name', 'Fetch Client Data')
.set('url', new URL({
schemes: [ 'https' ],
host: 'production.server.com',
path: '/path/to/new/request'
}))
.set('description', 'description of what we can fetch about a client')
.set('parameters', containers[1])
.set('bodies', new Immutable.List([ bodies[2] ]))
.set('responses', new Immutable.List([ responses[1], responses[2] ]))
.set('auths', new Immutable.List([ new Auth.OAuth2() ]))