Super Minimal NodeJS Web Server Framework
npm i git@github.service.anz:parasurv/xeno.git
Check samples for usage.
Create an app instance.
const app = new Xeno(options);
options
{
errorHandler: async (err, ctx) => {} // async function that will be called when any error occurs
}
Add a route to the application.
options
{
method: 'post', // defaults to get when not provided
url :'test/:testId', // suppports `/static`, `/dynamic/:param`, `/wildcard*`
handler: async (ctx) => {}, // optional async handler function executed on route
some: 'route metadata', // arbitrary metadata to add to `ctx.req.route`
other: 'property',
}
Add a hook to be executed at different phases of request.
hook : String // onRequest, onParse, onRoute, onSend, onResponse
handler : async (ctx) => {} // async function
Start the server.
Handlers (route and hook) are called with a ctx
object.
ctx = {
req: {
raw: <Raw NodeJS request>,
method: String, // request method
originalUrl: String, // request url (path + query string)
url | uri: String, // path component
search: String, // ?query=string
query: Object, // querystring as object
params: Object, // dynamic path params
headers: Object, // request headers
rawBody = [Buffer | String],
body: Any,
route: { // metadata about the current route
method: String,
path: String,
*: Any,
}
},
res: {
status(Number), // set reponse status code
header(String, String), // get or set response header name and value
headers(Object), // get all or set multiple response headers
removeHeader(String), // remove a response header
body: [Object | String | Buffer | Stream], // set response body
},
}
TODO