Skip to content

Response

JonathanMontane edited this page Apr 28, 2016 · 2 revisions

A Response component represents a possible response by the server to a Request. A Response has a few fields, named code, description, parameters, and bodies. Its core structure is very similar to that of a Request, using a ParameterContainer and a List of Body.

Import

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

Interface

Response extends Immutable.Record using the following pattern:

Class Response extends Immutable.Record({
    code: null,
    description: null,
    parameters: new ParameterContainer(),
    bodies: Immutable.List()
})

Fields

Response.code
  • Response.code expects an http code, e.g. 200 or 403. This Response.code is required.
Response.description
  • Response.description expects null or a string. It should describe the response.
Response.parameters
  • Response.parameters expects a ParameterContainer. It should contain all the Parameters necessary to describe the possible responses.
Response.bodies
  • Response.bodies expects an Immutable.List of Body. It should contain all the possible environments of the Response.

Example

Please note that this example is abstract, and is there purely to represent the different interactions with Body. 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 { Response } from './models/Core'

let response = new Response({
    code: 200,
    description: 'A simple description of what the Response returns',
    parameters: containers[0],
    bodies: new Immutable.List([ bodies[0], bodies[1]])
})

response = response
    .set('code', 404)
    .set('description', 'description of a 404 error')
    .set('parameters', containers[1])
    .set('bodies', new Immutable.List([ bodies[2] ]))
Clone this wiki locally