-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathweb.js
31 lines (25 loc) · 880 Bytes
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*global require, module*/
var ApiBuilder = require('claudia-api-builder'),
api = new ApiBuilder();
module.exports = api;
// set headers as key-value pairs using the success.headers property */
api.get('/status-code', function () {
'use strict';
return 'OK';
}, {success: 201 });
api.get('/error-code', function () {
'use strict';
throw 'Abort';
}, {error: 404});
// or use dynamic codes returning new api.ApiResponse(content, headers)
api.get('/programmatic-codes', function () {
'use strict';
return new api.ApiResponse('OK', {'Content-Type': 'text/plain'}, 202);
});
// dynamic headers also work with promises, just resolve with new api.ApiResponse
api.get('/programmatic-codes-promise', function () {
'use strict';
return Promise.resolve().then(function () {
return new api.ApiResponse('OK', {'X-Version': '303', 'Content-Type': 'text/plain'}, 400);
});
});