yeps-response
v0.2.0
Published
YEPS response
Downloads
4
Maintainers
Readme
YEPS Response
How to install
npm i -S yeps-response
How to use
You can put any type of response data: value, promise, error.
Without response
const App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');
const app = new App();
app.all([
error({ isJSON: true }),
logger(),
]);
app.then(async (ctx) => {
ctx.res.end('data');
return Promise.reject();
});
server.createHttpServer(app);
With response
const App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');
const response = require('yeps-response');
const app = new App();
app.all([
error({ isJSON: true }),
logger(),
]);
app.then(response());
app.then(async (ctx) => {
return ctx.response.resolve('data');
});
server.createHttpServer(app);
Custom response
const App = require('yeps');
const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');
const Response = require('yeps-response/response');
const app = new App();
app.all([
error({ isJSON: true }),
logger(),
]);
app.then(async (ctx) => {
const response = new Response(ctx);
return response.resolve('data');
});
server.createHttpServer(app);
Redirect
app.then(async (ctx) => {
return ctx.response.redirect(url = '/', code = 301);
});
Custom redirect
app.then(async (ctx) => {
const response = new Response(ctx);
return response.redirect(url = '/', code = 301);
});
Reject
If you need to send request and finish response
app.then(async (ctx) => {
return ctx.response.reject(data);
});