An open API service indexing awesome lists of open source software.

https://github.com/estrada9166/bonera


https://github.com/estrada9166/bonera

nodejs-framework webframework

Last synced: about 1 year ago
JSON representation

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')
})

```