Context
Descriptive full API of a Context.
A part of the context method is linked to the default ResponseHandler provided by Idylle. Specific method are design to adapt HTTP code when responding to an HTTP Request. For a better understanding feel free to check the HTTP Code Meaning.
Properties
data : Object { String: Any }
params : Object { String: String }
token: String
user: Object { String: Any }
session: Object { String: Any }
files: Array<File>
args: Object { String : Any }
criteria: Criteria
Methods
.error(code, message, ...args) -> Promise (rejected)
.error(code, message, ...args) -> Promise (rejected)
create a rejection with a ContextError.
...
execute: context => {
return User
.findById(context.params.id)
.then(u => u || context.error(404, 'user_not_found', { id: context.params.id }))
}
...
.ok(resource) -> resource
context.ok(resource) -> resource
changes the state of the context to tell the default ResponseHandler
that the response should be a 200 OK.
...
execute: context => {
return getCompetitionDetails()
.then(c => c || context.error(400, 'invalid competition'))
.then(context.ok);
...
.created(resource) -> resource
context.created(resource) -> resource
changes the state of the context to tell the default ResponseHandler
that the response should be a 201 Created and let the response body empty.
...
execute: context => {
return getCompetitionDetails()
.then(c => c || context.error(400, 'invalid competition'))
.then(context.created);
...
.partial(resource) -> resource
context.partial(resource) -> resource
changes the state of the context to tell the default ResponseHandler
that the response should be a 206 Partial.
...
execute: context => {
return getCompetitionList()
.then(c => c.truncated ? context.partial(c) : c);
...
.redirect(code=302, url) -> void
context.redirect(code, url) -> void
changes the state of the context to tell the default ResponseHandler
that the response should be a 301 Moved Permanently. Generally used when a deprecated method is still called from an old client.
...
execute: context => {
return context.redirect(null, '/competitions/list');
...
.stream(path | buffer) -> resource
context.stream(path | buffer) -> void
changes the state of the context to tell the default ResponseHandler
that a File
or Buffer
has to be downloaded from the given path.
...
execute: context => {
return getCompetitionList()
.then(c => c.truncated ? context.partial(c) : c);
...
.noContent(resource) -> resource
context.noContent(resource) -> resource
changes the state of the context to tell the default ResponseHandler
that the response should be a 204 No Content and let the response body empty.
...
execute: context => {
return getCompetitionList()
.then(c => c.truncated ? context.partial(c) : c);
...
Last updated