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

ng2-resource

v1.1.0

Published

Restful resource module for angular2

Downloads

13

Readme

ng2-resource

Restful resource module for angular2

To use the module install the module using below command

npm install --save ng2-resource

import the package using below syntax into your angular 2 app

//first import the rest provider
import {RestResource} from "ng2-resource";
.......

//inject rest service provider at app level
bootstrap(Demo,[
  HTTP_PROVIDERS,
  provide(RequestOptions,{useClass:JsonRequest}),
  RestResource
  ]);
// here you can inject any version of RequestOptions or Http the classes injected before rest resource will be used in the RestResource

//next implement data sevice provider using below in service file
import {RestResource} from 'ng2-resource';
import {Http} from '@angular/http';
import {Injectable} from '@angular/core';

@Injectable()
export class DataProvider extends RestResource{
  protected url : string = URL_PREFIX + "posts/:id";
  
  protected params : Object = { ':id' : '@id' }
  constructor(_http : Http) {
    // super is compulsory as Super class needs Http from the DI
    super(_http);
  }
}
  // now you can use the service to work as resource with your component
  @Component({
    selector: 'app',
    template: require('./posts_render.html') ,
    providers: [DataProvider]
  })

** check the demo folder for the reference on how to use **

It provides the following method out of box

  • query(params) get method
  • save(params) post method
  • update(params) put method
  • delete(params) delete method

It returns both Observables as well as promise in the response as below

  • resource.query().$observables which is inturn the object of observable so it can be subscribed
  • resource.query().$promise which is the promise object and it can be used to handle resolve or reject
  • all methods returns promise as well as observables

to run the example in demo field

  • clone the repo
  • npm install
  • npm start
  • navigate to http://localhost:8000 in browser

To Do:

  • add support for custom methods
  • add support for Request options specific to single request
  • add flexibility to remove super() call in constructor()
  • add support for configuration at run time