write

method
 write() 

Option name Type Description
output

If it is an object it will be serializeb with toPublicJSON, if it is a String it will be appended to the result, if it is a buffer it will replace the result

...args

any arguments to pass to the toPublicJSON method

Write data to the client

write(output) {
	if (typeof(output) == "object" && !(output instanceof Buffer)) {
		this._headers['Content-type']='application/json';
		CoreModel.__ctx = this;
		if (output instanceof CoreModel) {
			this._body = JSON.stringify(output);
		} else {
			this._body = this._webda.toPublicJSON(output);
		}
		CoreModel.__ctx = undefined;
		return;
	} else if (typeof(output) == "string") {
		if (this._body == undefined) {
			this._body = '';
		}
		this._body += output;
		return;
	} else {
		this._body = output;
	}
}

setHeader

method
 setHeader() 

Option name Type Description
header String

name

value String

Set a header value

setHeader(header,value) {
	this._headers[header]=value;
}

writeHead

method
 writeHead() 

Option name Type Description
httpCode Number

to return to the client

headers Object

to add to the response

Write the http return code and some headers
Those headers are not flushed yet so can still be overwritten

writeHead(httpCode, headers) {
	_extend(this._headers, headers);
	if (httpCode !== undefined) {
		this.statusCode = httpCode;
	}
}
Option name Type Description

For compatibility reason

cookie(param, value) {

end

method
 end() 

Option name Type Description

Flush the request

end() {

getService

method
 getService() 

Option name Type Description
name String

of the service

Get a service from webda

getService(name) {
	return this._webda.getService(name);
}

getLocale

method
 getLocale() 

Get the request locale if found

getLocale() {
	var locales = this._webda.getLocales();
	acceptLanguage.languages(locales);
	if (this.headers['Accept-Language']) {
		return acceptLanguage.get(this.headers['Accept-Language']);
	}
	return locales[0];
}

setExecutor

method
 setExecutor() 

Option name Type Description
executor

{object} Set the current executor for this context

setExecutor(executor) {
	this._executor = executor;
}