
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Brewski is a tiny node framework that assists in the creation of performant APIs when other options feel like overkill.
$ npm install brewski
# OR
$ yarn add brewski
const brewski = require('brewski')
const app = brewski({
env: {
port: 8888
}
})
const { log, env } = app
app.use((req, res, next) => {
log.info({ url: req.url })
next()
})
// Middleware with error
// app.use((req, res, next) => {
// next(new Error('Should be error'))
// })
// http://localhost:8888
app.get('/', (req, res) => {
res.send('Hi from brewski')
})
// http://localhost:8888/json
app.get('/json', (req, res) => {
res.send({ test: true })
})
// http://localhost:8888/status/tiaan
app.get('/status/:name', (req, res) => {
res.status(201).send({ name: req.params.name })
})
// http://localhost:8888/query?name=Tiaan
app.get('/query', (req, res) => {
res.send({ name: req.query.name })
})
// http://localhost:8888/html
app.get('/html', (req, res) => {
res.html('<h1>Hi</h1>')
})
// http://localhost:8888/redirect
app.get('/redirect', (req, res) => {
res.redirect(`http://localhost:${app.env.port}/`)
})
app.listen(app.env.port)
brewski(options): Object
Creates and returns a new brewski
object.
Options include:
logLevel
: String - Level of logging for pino logger. Defaults to info
.logStream
: Stream - Stream to log to. Defaults to process.stdout
.env
: Object - Environment variables to pass to envobj.https
: Object - Configuration options if https server should be created. Uses same options as http.createServer
defaultHandler
: function - Function to handle act as default route e.g.:
function defaultHandler(req, res) {
res.statusCode = 404
res.end()
}
Example:
const brewski = require('brewski')
const api = brewski({
logLevel: 'fatal',
env: {
port: 3000
}
})
brewski.use(middleware: Function): Object
Add new middleware to the stack. Middleware is processed in the order they are added. Since the middleware function matches that of express, existing packages can be used with no additional configuration:
const brewski = require('brewski')
const api = brewski()
const helmet = require('helmet')
api.use(helmet())
brewski.route(method: String|Array, route: String, handler: Function)
Creates a new route. Brewski uses find-my-way to handle routing and supports parametric, wildcard and parametric with regex routes e.g:
const brewski = require('brewski')
const api = brewski()
api.get('/foo/:baz', (req, res) => {
res.send(req.params)
})
api.get('/baz/*', (req, res) => {
res.send(req.params)
})
api.get('/baz/:thing(^\\d+).png', (req, res) => {
res.send(req.params)
})
You can also use the shorthand methods to declare your routes e.g:
const brewski = require('brewski')
const api = brewski()
function handler(req, res) {
res.send({success: true})
}
api.get('/foo', handler)
api.post('/foo', handler)
api.patch('/foo', handler)
api.delete('/foo', handler)
api.head('/foo', handler)
api.put('/foo', handler)
api.option('/foo', handler)
api
.get('/baz', handler)
.post('/baz', handler)
brewski.server
Access to the HTTP server instance created by brewski. See node docs for more information.
brewski.listen(port, address, callback)
Starts the created server on provided port and address. If port is not provided, env.PORT
is used. callback
is called after server starts listening.
Example:
const brewski = require('brewski')
const api = brewski()
api.listen()
// api.listen(3000)
// api.listen(3000, () => console.log('Listening on port 3000'))
brewski.log
Provides access to the pino logger instance e.g:
const brewski = require('brewski')
const api = brewski()
api.log.info({foo: true})
See pino documentation for more options.
brewski.env
Provides access to envobj object.
Benchmark is run using autocannon with 200 concurrent connection for 30s. To run the benchmark:
npm i && npm run benchmark:
# Or
yarn && yarn benchmark
Results from latest benchmark (MacBook Air (13-inch, 2017), 1,8 GHz Intel Core i5, 8 GB 1600 MHz DDR3):
Stat Avg Stdev Max
Latency (ms) 18.02 6.88 276
Req/Sec 10863.34 1655.63 12607
Bytes/Sec 1.58 MB 241 kB 1.84 MB
326k requests in 30s,
This package is inspired and influenced by fastify.
Contributions are welcome!
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Or open up a issue.
Licensed under the MIT License.
FAQs
A artisan web microframework
The npm package brewski receives a total of 0 weekly downloads. As such, brewski popularity was classified as not popular.
We found that brewski demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.