Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joaquimnet/ponaserv
Easily map routes to request handlers in your express app.
https://github.com/joaquimnet/ponaserv
express nodejs
Last synced: 6 days ago
JSON representation
Easily map routes to request handlers in your express app.
- Host: GitHub
- URL: https://github.com/joaquimnet/ponaserv
- Owner: joaquimnet
- License: mit
- Created: 2020-09-27T14:38:37.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T10:27:26.000Z (about 2 months ago)
- Last Synced: 2024-09-16T12:04:57.208Z (about 2 months ago)
- Topics: express, nodejs
- Language: TypeScript
- Homepage: ponaserv.vercel.app
- Size: 395 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Ponaserv
Easily map routes to request handlers.
## How to use
```javascript
/* server.js */
const { ponaserv } = require('ponaserv');
const express = require('express');
const path = require('path');const app = express();
ponaserv(app, { services: path.join(__dirname, 'services') });
app.listen(3000, () => {
console.log('App listening on port 3000');
});
```## Service example
```javascript
/* services/hello.js */
const express = require('express');module.exports = {
name: 'hello-world',
routes: {
'GET /': 'sayHello',
'GET /:message': 'specialHello',
'POST /': 'jsonIsCool',
'GET /math': 'math',
},
actions: {
sayHello(req, res) {
res.send('Hello World!');
},
specialHello(req, res) {
const { message } = req.params;
res.send(message.toUpperCase());
},
jsonIsCool: {
middleware: [express.json()],
handler(req, res) {
const { body } = req;
res.send({ yourData: body });
}
},
math: {
middleware: [express.json()],
params: {
a: 'number',
b: 'number',
$$strict: true,
},
handler(req, res) {
const params = {...req.params, ...req.body, ...req.query};
res.send(this.calc(params.a, params.b));
}
}
},
methods: {
calc(a, b) {
return a + b;
}
}
}
```## Getting Started
Head to our [documentation](https://ponaserv.vercel.app) to learn more about ponaserv.
## License
Ponaserv is [MIT licensed](./LICENSE).