Below is a list of all available functions after constructing a new NextBootstrap()
bootstrap.addMiddleware(middleware) // Adds an Express.JS Middleware
bootstrap.addGraphQLField(field) // Adds a custom GraphQL Compose Field
bootstrap.get(route, callback) // Adds a custom Express.JS HTTP GET route
bootstrap.post(route, callback) // Adds a custom Express.JS HTTP POST route
bootstrap.put(route, callback) // Adds a custom Express.JS HTTP PUT route
bootstrap.patch(route, callback) // Adds a custom Express.JS HTTP PATCH route
bootstrap.delete(route, callback) // Adds a custom Express.JS HTTP DELETE route
bootstrap.init(completed) // Initializes the bootstrap
bootstrap.exit() // Clean exits the bootstrap
Below are some examples based on the functions above:
This example creates a new GraphQL field called example
with the type String
and will return the result: Hello World!
when queried through GraphQL
bootstrap.addGraphQLField({
example: {
name: 'example',
type: 'String',
resolve: async () => {
return 'Hello World!';
}
}
});
Additional GraphQL Compose Documentation: https://graphql-compose.github.io/docs/api/Resolver.html
This example creates a middleware that logs incoming every request
bootstrap.addMiddleware(function (req, res, next) {
console.log(`[${req.method}] ${req.originalUrl}`);
next();
});
Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.use
This example creates the /test
route that will respond with Hello World!
bootstrap.get('/test', function (req, res) {
res.send('Hello World!');
});
Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.get.method
This example creates the /test
route that will respond with OK
and is able to read the body that was send as JSON
bootstrap.post('/test', function (req, res) {
console.log(req.body);
res.send('OK');
});
Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.post.method
Last modified | Friday, April 30, 2021, 12:00:21 PM UTC |
Last author | Colin van Eenige |
Commit ID | 4c7a701 |