https://github.com/estrada9166/bonera
https://github.com/estrada9166/bonera
nodejs-framework webframework
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/estrada9166/bonera
- Owner: estrada9166
- Created: 2017-06-23T19:16:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-05T00:15:46.000Z (over 8 years ago)
- Last Synced: 2025-02-23T11:07:37.807Z (about 1 year ago)
- Topics: nodejs-framework, webframework
- Language: JavaScript
- Size: 6.75 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```javascript
app.use((req, res) => {
//create the middleware to use
})
```
##### access the params of the url using
```javascript
req.params
```
##### access the query of the url using
```javascript
req.query
```
##### access the form of the post using
```javascript
req.body
```
##### get
```javascript
app.get('/path', callback)
```
##### put
```javascript
app.put('/path', callback)
```
##### patch
```javascript
app.patch('/path', callback)
```
##### post
```javascript
app.post('/path', callback)
```
##### delete
```javascript
app.delete('/path', callback)
```
##### start the server
```javascript
app.listen(port, callback)
```
#### e.g
------
```javascript
const bonera = require('bonera');
const app = bonera();
//Create a middleware to display the respond as a JSON
app.use((req, res) => {
res.json = (val) => res.end(JSON.stringify(val));
});
app.get('/', (req, res) => {
console.log('Hello world');
});
//if the path is /user/?message=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')
})
```