Bonera Web Framewor
Minimalist web framework for node.js
Installation
$ npm install bonera
Features
- Use middlewares
- Get
- Put
- Patch
- Post
- Delete
- Liste
create a middleware
app.use((req, res) => {
})
access the params of the url using
req.params
access the query of the url using
req.query
access the form of the post using
req.body
get
app.get('/path', callback)
put
app.put('/path', callback)
patch
app.patch('/path', callback)
post
app.post('/path', callback)
delete
app.delete('/path', callback)
start the server
app.listen(port, callback)
e.g
const bonera = require('bonera');
const app = bonera();
app.use((req, res) => {
res.json = (val) => res.end(JSON.stringify(val));
});
app.get('/', (req, res) => {
console.log('Hello world');
});
app.get('/greet', (req, res) => {
console.log(`The message ${req.query.message}`);
});
app.get('/user/:id', (req, res) => {
console.log(`The user id is ${req.params.id}`);
});
app.post('/user', (req, res) => {
console.log('A post has been made, use req.body to access to the data')
});
app.put('/user/:id', (req, res) => {
console.log('A put has been made, access to the params with req.params.id');
});
app.patch('/user/:id', (req, res) => {
console.log('A patch has been made, access to the params with req.params.id');
});
app.delete('/user/:id', (req, res) => {
console.log('A delete has been made, access to the params with req.params.id');
});
app.listen(8080, () => {
console.log('server running on port 8080')
})