npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

henhouse

v2.0.46

Published

A Microservices Framework for REST APIs

Downloads

65

Readme

Henhouse

A Microservices Framework for REST APIs

Installation

Install using npm:

npm install henhouse

API Reference

henhouse

import module

const Henhouse = require('henhouse')

constructor

const myService = new Henhouse({
  servicePath: 'my-service' // null by default 
})

listen

listen at a specified port

myService.listen(3000)

close

listen at a specified port

myService.close()

get | put | post | patch | delete

  • Match URL patterns to callback functions
myService
  .get('/foo', async (ctx, next) => {
    ctx.body = 'foo';
  })
  .post('/foo', async (ctx, next) => {
    ctx.body = `Body: ${ JSON.stringify(ctx.request.body) }`;
  })
  .get('/bar/:id', async (ctx, next) => {
    ctx.body = 'bar: ' + this.params.id;
  })
  .listen(3000)
  • Match model name to callback functions
myService
  .get('foo', async (ctx, next, model, id) => {
    ctx.body = await model.query(ctx.$queryOptions, id)
  })
  .post('foo', async (ctx, next, model) => {
    ctx.body = await model.create(ctx.$requestBody)
  })
  .patch('foo', async (ctx, next, model, id) => {
    await model.update(ctx.$requestBody, id)
    ctx.body = 'ok'
  })
  .delete('foo', async (ctx, next, model, id) => {
    await model.remove(id)
    ctx.body = 'ok'
  })
  .listen(3000)
url query options
  • specify attributes white list
http://localhost:3000/foos?fields=a,b
  • if "foo" got a associations named "bar"
http://localhost:3000/foos?fields=a,b,bar.c,bar.d
  • put some query conditions
http://localhost:3000/foos?a=1&b=*bar

if model "foo" got a db engine behind, it may query like:

 select * from foo
 where foo.a=1 and foo.b like '%bar'
  • it can also support nested object in query
http://localhost:3000/foos?a=1&bar.b=2,3,4

it may run a sql like:

 select * from foo
 inner join bar on bar.id = foo.bar_id
  and bar.b in (2,3,4)
 where foo.a=1
  • order
http://localhost:3000/foos?order=name,-beginDate

it's may run a sql like:

 select * from foo
 order by name, begin_date desc

static

serving static files

const { resolve } = require('path');

const myService = new Henhouse();
myService
  .getStatic({ root: path.resolve(__dirname, 'static-root') })
  .getStatic('/foo', { root: path.resolve(__dirname, 'static-foo') })
  .getStatic('/bar') // __dirname/bar
  .listen(3000)

HttpException

const HttpException = Henhosue.HttpException
new henhouse.HttpException(status, message, stackEnumerable)

create a new http exception

| Param | Type | Description | | --------------- | -------------------- | ---------------------------------------- | | status | Numeric | http status code | | message | String | customized error message | | stackEnumerable | Boolean | include the stack info or not. false as default |

throw new HttpException(400, 'oops...');