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

yeps-restify

v0.1.0

Published

YEPS Restify

Downloads

9

Readme

YEPS Restify

REST API request aggregate

NPM

npm version Build Status Coverage Status Linux Build Windows Build

Dependency Status devDependency Status NSP Status

Known Vulnerabilities License GitHub stars GitHub forks GitHub issues Twitter

How to install

npm i -S yeps-restify

How to use

Config

config/default.json

{
  "restify": {
    "restApiServerUri": "http://localhost/"
  }
}

app.js

const App = require('yeps');

const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');

const restify = require('yeps-restify');

const app = new App();

app.all([
  error({ isJSON: true }),
  logger(),
]);

app.then(restify());

server.createHttpServer(app);

Custom router

app.then(async (ctx) => {
  if (ctx.req.url === '/restify') {
    return restify()(ctx);
  }
  
  return app.resolve();
});

With router

const Router = require('yeps-router');

const router = new Router();

router.get('/restify').then(restify());

app.then(router.resolve());

Example

app

const App = require('yeps');
const Router = require('yeps-router');

const error = require('yeps-error');
const logger = require('yeps-logger');
const server = require('yeps-server');

const restify = require('yeps-restify');

const app = new App();
const router = new Router();

app.all([
  error({ isJSON: true }),
  logger(),
]);

router.get('/restify').then(restify());
    
app.then(router.resolve());

// REST API

const users = [
  { id: 1, name: 'User 1' },
  { id: 2, name: 'User 2' },
];
const customers = [
  { id: 1, name: 'Customer 1' },
  { id: 2, name: 'Customer 2' },
];

const countries = [
  { id: 1, name: 'Country 1' },
  { id: 2, name: 'Country 2' },
];

const restRouter = new Router();

restRouter.get('/api/users').then(async (ctx) => {
  ctx.res.end(JSON.stringify(users));
});

restRouter.get('/api/customers').then(async (ctx) => {
  ctx.res.end(JSON.stringify(customers));
});

restRouter.get('/api/customers/:id').then(async (ctx) => {
  const id = parseInt(ctx.request.params.id, 10);
  const response = customers.find(customer => customer.id === id);
  ctx.res.end(JSON.stringify(response));
});

restRouter.get('/api/countries').then(async (ctx) => {
  ctx.res.end(JSON.stringify(countries));
});

app.then(restRouter.resolve());

server.createHttpServer(app);

Request

/restify?users=api/users&customer=api/customer/1&countries=api/countries

Response

{
  "data": {
    "users": [
      { "id": 1, "name": "User 1" },
      { "id": 2, "name": "User 2" }
    ],
    "customer": {
      "id": 1,
      "name": "Customer 1"
    },
    "countries": [
      { "name": "Country 1" },
      { "name": "Country 2" }
    ]
  }
}

With error

{
  "data": {
    "users": [
      { "id": 1, "name": "User 1" },
      { "id": 2, "name": "User 2" }
    ],
    "customer": null,
    "countries": [
      { "name": "Country 1" },
      { "name": "Country 2" }
    ]
  },
  "error": {
    "customer": {
      "message": "Not Found"
    }
  }
}

YEPS documentation