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 🙏

© 2026 – Pkg Stats / Ryan Hefner

simpleresource

v1.0.6

Published

Connects business objects and REST web services for Angular.js

Readme

SimpleResource

CircleCI npm version Bower version codecov

SimpleResource aims to provide a simple way to connect your Angular application to a RESTful backend API.

Installation

You can use either bower

bower install simpleresource --save

or npm to install the package

npm install simpleresource --save

Quick setup

  1. Start by defining your API domain by injecting SimpleResourceSettingsProvider in a angular.config block:
angular
  .module('MySuperApp', [])
  .config(function (SimpleResourceSettingsProvider) {
    SimpleResourceSettingsProvider.configure({
      apiUrl: 'https://api.domain.com' // use globally accross your application
    })
  })
  1. Define a service that will act as a Model for your resource:
angular
  .module('MySuperApp')
  .service('User', function (SimpleResource) {
    return new SimpleResource('user').instanceMethods({
      /**
       * Attach fullname() on any instance of user.
       *
       * @return {String}
       */
      fullname: function () {
        return [this.lastname, this.firstname].join(' ')
      }
    })
  })
  1. Inject this service whenever you need to retrieve data from your API:
angular
  .module('MySuperApp')
  .controller('UsersController', function (User) {
    var vm = this

    // GET /users
    User.all(function (users) {
      // do something
      // For example, display the first user's fullname
      console.log(users[0].fullname())
    })

    // Get /users/10
    User.find(10, function (user) {
      user.username = 'chuck.norris'
      user.save() // PATCH /users/10
    })

    var user = new User({ username: 'bruce.lee' })
    user.save()   // POST /users
    user.delete() // DELETE /users/100
  })

SimpleResource API

SimpleResource has been built to be simple and easy to implement and use. It's API remain very simple on purpose. If you are familiar with Angular $resource, then you know already how to use it.

Constructor

SimpleResource constructor take only one argument that can either be a String or an Object.

As object

angular
  .module('MySuperApp')
  .service('User', function (SimpleResource) {
    return new SimpleResource({
      baseUrl:   'https://api.domain2.com',
      namespace: 'user',
      params:    { id: '@id' },
      url:       '/users/:id',
    })
  })

baseUrl

Allows you to override the global apiUrl defined in the angular.config block (see the Quick setup section). It gives you the flexibility to connect to multiple backend API.

namespace

Allows you to define a namespace for your resource. If you are using the SimplePaginator service to handle your pagination, your pagination values will be wrapped under this namespace. Also, if your API is build using Ruby on Rails, POST and PUT|PATCH requests will be by default wrapped under this namespace. For example, if your namespace is blog, then data send will look like:

{
  "blog": {
    "title": "Blog title",
    "description": "Blog description"
  }
}

Please note that it is possible to avoid this behavior by defining a transformRequest method on SimpleResourceSettingsProvider.configure (see the configuration section) and change the way data are sent to the server.

params

Default values for url parameters. As SimpleResource is based on Angular $resource (paramDefaults), you are welcome to take a look at the offical documentation at https://docs.angularjs.org/api/ngResource/service/$resource

url

A parameterized URL template with parameters prefixed by :`` as in /user/:username`. As SimpleResource is based on Angular $resource (paramDefaults), you are welcome to take a look at the offical documentation at https://docs.angularjs.org/api/ngResource/service/$resource

As string

angular
  .module('MySuperApp')
  .service('User', function (SimpleResource) {
    return new SimpleResource('user')
  })

When you instanciate using a string, you need to specify the singular name of your resource. If you deal with posts for a blog, then you need to use post for example.

This will try to generate an object-like configuration that looks like this:

{
  namespace: 'user',
  params:    { id: '@id', action: '@action' },
  url:       '/users/:id/:action'
}

Note that using a string for the constructor will use the global apiUrl defined in the angular.config block.

Todos

  • [ ] Improve documentation