You can setup custom REST endpoints like this:
const bootstrap = new NextBootstrap(__dirname, process.cwd(), nextConfig);
// HTTP GET
bootstrap.get('/api/test', (req, res) => {
res.json({
message: 'OK'
});
});
// HTTP POST
bootstrap.post('/api/test', (req, res) => {
res.json({
message: 'OK'
});
});
// HTTP PUT
bootstrap.put('/api/test', (req, res) => {
res.json({
message: 'OK'
});
});
// HTTP PATCH
bootstrap.patch('/api/test', (req, res) => {
res.json({
message: 'OK'
});
});
// HTTP DELETE
bootstrap.delete('/api/test', (req, res) => {
res.json({
message: 'OK'
});
});
bootstrap.init();
All bootstrap API call's will respond with this basic structure:
{
"status": 1000,
"result": {}
}
The status code in the example above is a Bootstrap standard code.
These can be used anywhere in your application like this:
const statusCode = require('@dpdk/bootstrap/dist/status');
console.log('status', statusCode(1000)); // Outputs { code: 1000, message: '' } in production. Outputs { code: 1000, message: 'Request completed' } in development
All status codes can be found below:
| Status Code | Status Message | |:------------ |:------------------------- | | 1000 | Request completed | | 1010 | Account activated | | 1011 | Login successful | | 1012 | Password reset successful | | 1020 | Email has been send | | 1030 | Form has been submitted |
| Status Code | Status Message | |:------------ |:------------------------- | | 5000 | Server error | | 5010 | Account not found | | 5011 | Account not activated | | 5012 | Login incorrect | | 5013 | Email/Username not found | | 5020 | Error sending email | | 5030 | Error submitting form | | 5031 | Error sending email | | 5032 | Invalid fields | | 5033 | File to large | | 5034 | Invalid file type | | 5035 | CSRF validation failed | | 9999 | Generic Error |
JSON-API Documentation: https://jsonapi.org/
OpenAPI Documentation: https://github.com/OAI/OpenAPI-Specification
Last modified | Friday, April 30, 2021, 12:00:21 PM UTC |
Last author | Colin van Eenige |
Commit ID | 4c7a701 |