Events
Http
Nodejs
Install
npm i squeezer-event-node --save
src/handler.js
'use strict';
import event from 'squeezer-event-node';
import vars from './.vars';
export function handler(...args) {
event(vars, (req, res) => {
res.send(200, 'hello!');
}, ...args);
}
Object
req : Properties
Name | Type | Description |
---|---|---|
body |
Object
|
http body object sent by request |
method |
string
|
Http method - GET, PUT, POST, DELETE, etc.. |
path |
string
|
A cleaned url string |
url |
string
|
base resource of url |
headers |
Object
|
header object containing all header information |
params |
Object
|
parameters object from url path -
/resource/{id}
=
{ id: <value> } |
query |
Object
|
query parameters object from url - /resource?sort=asc = { sort: ‘asc’ } |
clientIpAddress |
string
|
Client ip address -
x.x.x.x |
clientCountry |
string
|
Client ip address country -
US |
Object
res : Properties
Name | Type | Description |
---|---|---|
send |
function
|
Sends the HTTP response. |
json |
function
|
Sends the HTTP JSON response. |
header |
function
|
Set header
key
to
value
, or pass an object of header fields. |
res.send(statusCode, body)
Formats statusCode, body to be sent as a HTTP response back to api consumer (Api Gateway, Google Endpoint). The body parameter can be a a String, an object, or an Array.
Param | Type | Description |
---|---|---|
statusCode |
number
|
Http Response code |
body |
string
|
Object
|
Array
|
Response body |
Kind: public function
Returns: Object
- response HTTP response object formatted for Api Gateway.
res.json(statusCode, body)
Similar as res.send
with the difference that the response will be in JSON content-type .
res.charset(val)
Set the charset
for the content-type header , default is utf-8
res.header(key, value)
Set header key
to value
, or pass
an object of header fields.
Examples:
res.header('Content-Type', 'application/json');
res.header('foo', 'bar');