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

ritley

v1.0.0

Published

fast REST builder

Downloads

2

Readme

version dependencies downloads

About

Ritley is a small package with only two dependencies that allows you to create REST applications in no time. You can define Resources as entities which handle requests to the server. Create as many instances as you need. Also you can extend (inherit) previous entities to build more complex behaviors. Ritley is build on top kaop OOP features. You may use this package to provide Dependency Injection, Method overriding, Transaction Advices, etc.

Disclaimer

Ritley is still on development and it doesn't provide SSL support yet so, for now, I don't recommend use it on serious production environments.

Getting Started

Install ritley: npm install ritley --save

Create a file structure like this:

├── public
│   └── index.html
├── ritley.cfg.js
├── start.js
└── package.json

Ritley expects to receive a configuration file with some parameters which define its behavior such as these:

// ./ritley.cfg.js
module.exports = {
  "base": `/rest`,                  // api resource prefix
  "static": `${__dirname}/public`,  // static directory to serve your front
  "port": 8080,                     // port to be used by ritley to run the app
}

First you should use setConfig to set up providers that will take care of configuring modules. Start defining your resource by extending from AbstractResource. Then you can create instances providing your entity name to be handled:

// ./start.js
const { setConfig, AbstractResource, extend } = require("ritley");

setConfig(require("./ritley.cfg")); // load configuration

const BasicResource = extend(AbstractResource, {
  get(request, response) {          // curl localhost:8080/rest/dummy?id=1 -X GET -v
    console.log(this.$abspath);     // "rest/dummy"
    console.log(this.$uri);         // "dummy"
    console.log(request.query);     // { "id": 1 }
    response.statusCode = 200;
    response.end();
  },
  post(request, response) {         // curl localhost:8080/rest/dummy -X POST --data '{ "something": 1 }' -v
    console.log(request.toJSON());  // { "something": 1 }
    response.statusCode = 200;
    response.end();
  },
});

new BasicResource("dummy");

In deep (wip)

Ritley rely on NodeJS default http package to perform 99% of its operations. This library is only a shell that helps you organize your code into OOP patterns and Resources. Say you have the following configuration file:

{
  "base": `/api`,
  "static": `${__dirname}/dist`,
  "port": 8080,
}
  • If you browse localhost:8080 ritley will try to search your /dist/index.html

  • If you browse localhost:8080/js/bundle.js ritley will try to search your /dist/js/bundle.js

Basically if any route doesn't start by the api prefix which is base, then ecstatic package will try to resolve it using configuration's static entry.

So, if you're requesting a POST to localhost:8080/api/resource1 from anywhere, lets say axios within your JavaScript application, ritley will look if there is any resource listening that route for that HTTP verb.

You may create different resources by extending from basic ones if you need to handle auth or other complex behavior.

Docs

Ritley uses Node's default http package to manage all stuff. You don't have to worry about learn another API but this one that you may already known.

For convenience inside any AbstractResource subclass you can access:

this.$uri       // resource name
this.$srv       // node http server (singleton)
this.$cfg       // ritley confg object (full)
this.$abspath   // `${this.$cfg.base}/${this.$uri}`;

Examples

Working 'getting started' example/ folder

Roadmap

  • Create examples for advanced behaviors
  • Setup testing
  • SSL support