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

rested-resources

v0.1.0

Published

RESTed Resources is a client-side REST-based API layer for your resources. Conceptually similar to `ngResource`, it handles http requests and URL building to give you simple, consistent logic.

Downloads

2

Readme

RESTed Resources

RESTed Resources is a client-side REST-based API layer for your resources. Conceptually similar to ngResource, it handles http requests and URL building to give you simple, consistent logic.

Resources automatically generate URLs based on their hierarchy. Requests are managed by superagent and results/errors are handled via Promises.

Installation

  • npm install rested-resources --save
  • or for yarn users: yarn add rested-resources

Usage

While RESTed Resources works as a client-side library, it's built as an NPM module with the assumption you're using webpack or a related library to compile your application.

Examples below are written with some ES6, which will require babel to transpile.

Import the resource classes:

import { IdentifiedResource, ResultsResource } from 'resource';

While you can export resource classes directly, you'll likely want to use a factory to help setup relationships.

-- student.js
export default class Student extends IdentifiedResource {}

-- students.js
export default class Students extends ResultsResource {}

-- course.js:
import Student from './student';
import Students from './students';

class Course extends IdentifiedResource {}

export function(data) {
    let resource = new Course(data);

    resource.nest(Student);
    resource.nest(Students);

    return resource;
}

You now have everything needed to interact with these resources.

Querying for all students in a course:

var course = new Course({ courseId: 'history-101' });

// performs: GET /courses/history-101/students
course.students.query().then((results) => {
    // results will be the resulting JSON
});

Query for a specific student's course data:

var course = new Course({ courseId: 'history-101' });
var student = new course.Student({ studentId: 1234 });

// performs: GET /courses/history-101/students/1234
student.get().then((result) => {
    // result will be the resulting JSON
});

Create a new student record:

var student = new Student({ name: 'Kermit' });

// performs: POST /students
student.save().then((result) => {});