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

relaxjs

v0.3.3

Published

A library written in Typescript to build RESTful services in node.js

Downloads

19

Readme

relaxjs

Welcome to repo for the relaxjs node framework.

Introduction

To install the framework use npm:

npm install relaxjs

You can use relaxjs directly in your Javascript code as well as in your TypeScript projects.

The following are two basic examples on how to use relaxjs. These are just very basic examples. I am writing more samples that shows how to use every aspect of relaxjs in this repo

In Javascript

The main element of a server created with relaxjs is the resource. We add a resource to a site and we give it some data.

// hello_relaxjs.js
var r = require('relaxjs');

var site = r.site('simpleSite');

site.add( {
  name: 'hello',
  outFormat: 'application/json',
  data: { message: "Hello relaxjs !" }
});
site.serve().listen(9000);

Then start you server:

node hello_relaxjs.js

In Typescript

The Typescript version of the same example would look like this:

///<reference path='../node_modules/relaxjs/dist/relaxjs.d.ts' />

import * as r from 'relaxjs';

var site = r.site('simpleSite');
site.add( {
  name: 'hello',
  outFormat: 'application/json',
  data: { message: "Hello relaxjs !" }
});
site.serve().listen(9000);

With Typescript you need to compile the file and generate the Javascript file:

tsc -m commonjs -t es5 hello_relaxjs.ts

Then start you server:

node hello_relaxjs.js

Main Concepts

So relaxjs is a simple node framework for building true RESTful web server apps. The core elements of a relaxjs application are:

  • the site
  • its resources

The site listens to HTTP requests and direct them to the resources according to their hirearchical location within the site. The resource represent a unit accessible through a specific URI through one of the accepted HTTP verbs: GET, POST, PUT, PATCH and DELETE.

In addition you can add filter to a site to analyze any HTTP request before it reaches a resource and either stop these requests or add data to be pass to the resource themselves.

All the code for your web service resides inside the resources.

Some of the major features include:

  • Allows to define response functions inside a resource to respond to HTTP request (onGet, onPost, onDelete and onPatch)
  • Recources can be nested inside other resources.
  • Resource response functions can set headers and defines the mime types of their responses.
  • Allows to define filters functions that are called before requests reach any resources and can stop requests or gather data for the resources themselves.
  • Support streaming out of the box. So you can just respond to a request with a node stream and let relaxjs take care of the rest.
  • Support CORS protocol to build server REST applications that can be called by other sites.
  • Support html views compiled by lodash template function.

For examples on each one these features visit the relaxjs-examples repo.

License: MIT