Skip to content

Request

JonathanMontane edited this page May 9, 2016 · 2 revisions

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.

Import

/* if in src/ */
import { Request } from './models/Core'

Interface

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
})

Fields

Request.id
  • Request.id is a unique identifier for the Request.
Request.name
  • Request.name is simple name to identify the request. there are no uniqueness requirements.
Request.url
  • Request.url expects a URL object. Required.
Request.method
  • Request.method expects one of the methods defined in RFC#2616 and its extension RFC#5789. Required
Request.description
  • Request.description expects a description of the intent of the Request.
Request.parameters
  • Request.parameters expects a ParameterContainer. This ParameterContainer should contain all the possible Parameters that can be used in this Request.
Request.bodies
  • Request.bodies expects an Immutable.List of Body objects. This List should contain all the possible environments which can be used with the Request.
Request.auths
  • Request.auths expects an Immutable.List of Auth objects. These authentication methods are orthogonal to Request.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
  • Request.responses expects an Immutable.List of Response objects, that describe the possible responses of to that Request.
Request.timeout
  • Request.timeout defines the time in seconds after which the Request should time out.

Example

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() ]))
Clone this wiki locally