https://github.com/emkay/theodore
http framework
https://github.com/emkay/theodore
framework http-server
Last synced: 6 months ago
JSON representation
http framework
- Host: GitHub
- URL: https://github.com/emkay/theodore
- Owner: emkay
- License: mit
- Created: 2018-03-03T03:32:43.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:49:50.000Z (over 3 years ago)
- Last Synced: 2024-12-29T06:02:26.181Z (about 1 year ago)
- Topics: framework, http-server
- Language: JavaScript
- Size: 1.09 MB
- Stars: 37
- Watchers: 3
- Forks: 7
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# theodore
super fast http framework
[](https://nodejs.org/api/documentation.html#documentation_stability_index)
[](https://travis-ci.org/emkay/theodore)
[](http://standardjs.com/)
[](https://github.com/conventional-changelog/standard-version)
## Install
`npm i theodore`
## Use
```javascript
const Theodore = require('theodore')
const app = new Theodore()
app.get('/', (req, res, params) => res.send('hello world', 200))
app.get('/status', (req, res, params) => res.send('OK', 200))
app.get('/cats', (req, res, params) => res.json(['theodore', 'sally', 'glory'], 200))
app.listen()
```
## How?
`theodore` uses [`turbo-http`](https://github.com/mafintosh/turbo-http) under the hood and adds a router and similar API to other http frameworks. It also adds some convenience methods that allow you to send JSON responses by using the [`fast-safe-stringify`](https://www.npmjs.com/package/fast-safe-stringify) package. When parsing JSON data it is using [`fast-json-parse`](https://www.npmjs.com/package/fast-json-parse).
## API
#### `app = new Theodore()`
Create a new server.
#### `app.{get,post,put,delete}(route, handler(req, res, params))`
Create a route that matches the method and `route`.
#### `req.body`
If the request has a body it will be parsed based on content type and placed in `req.body`.
#### `res.json(json, statusCode)`
Will set the content type and stringify the JSON for you.
#### `res.send(data, statusCode)`
Send a response down the line.