A lightweight HTTP library for NodeJS
With NPM:
$ npm install racer-http --save
Or with Yarn:
$ yarn add racer-http
Note: This example uses Babel, but of course you can use the library without Babel.
import { Server, Router } from '../lib/'
import { join } from 'path'
Router.registerMiddleware('/', (req, res, next) => {
if(req.param('name') === 'google') {
return res.redirect('https://google.com')
}
return next(req, res)
})
Router.get('/', (req, res) => {
const name = req.name
res.view('app.pug', { name })
})
Router.post('/posts', (req, res) => {
const { title, content } = req.params
res.json({ error: false, message: 'Post created'})
})
new Server(8000)
.debug(true)
.start()
Coming up!