rest-api-starter
Version:
Rest API starter kit.
67 lines (52 loc) • 1.65 kB
JavaScript
/**
* Created by svinci on 1/13/17.
*/
;
const serverBuilder = require('../app/server');
const store = [];
const router = (app) => {
app.get('/client-get-test', (request, response, next) => {
response.send(store);
});
app.post('/client-post-test', (request, response, next) => {
store.push(request.body);
response.send(request.body);
});
app.put('/client-put-test', (request, response, next) => {
store.push(request.body);
response.send(request.body);
});
app.patch('/client-patch-test', (request, response, next) => {
store.push(request.body);
response.send(request.body);
});
app.delete('/client-del-test', (request, response, next) => {
response.send({});
});
app.get('/bad-request-endpoint', (request, response, next) => {
next({
'name': 'validation.error',
'errors': [
'validation.error.schema.name'
]
});
});
app.get('/not-found-endpoint', (request, response, next) => {
next({
'name': 'document.not.found',
'detail': {
'id': 3
}
});
});
app.get('/endpoint-that-takes-1s', (request, response, next) => {
setTimeout(() => response.send({}), 1000);
});
app.get('/endpoint-that-takes-half-s', (request, response, next) => {
setTimeout(() => response.send({}), 500);
});
app.get('/internal-server-error-endpoint', (request, response, next) => {
throw Error('Oops!');
});
};
module.exports = () => serverBuilder(router);