lambda-envelope
Version:
Envelope for AWS Lambda responses that supports raw invocation response parsing
29 lines (22 loc) • 506 B
JavaScript
;
const DEFAULT_ENCODING = 'identity';
class Response {
constructor({ body, encoding, statusCode } = {}) {
this.statusCode = statusCode || 200;
this.encoding = encoding || DEFAULT_ENCODING;
this.body = typeof body !== 'undefined'
? body
: {};
}
toJSON() {
return {
statusCode: this.statusCode,
encoding: this.encoding,
body: this.body
};
}
toString() {
return JSON.stringify(this.toJSON());
}
}
module.exports = Response;