This repository was archived by the owner on Sep 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
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.
/* if in src/ */
import { Response } from './models/Core'Response extends Immutable.Record using the following pattern:
Class Response extends Immutable.Record({
code: null,
description: null,
parameters: new ParameterContainer(),
bodies: Immutable.List()
})-
Response.codeexpects an http code, e.g.200or403. ThisResponse.codeis required.
-
Response.descriptionexpectsnullor astring. It should describe the response.
-
Response.parametersexpects aParameterContainer. It should contain all the Parameters necessary to describe the possible responses.
-
Response.bodiesexpects an Immutable.List ofBody. It should contain all the possible environments of the Response.
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] ]))