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

ng-restify

v1.4.0

Published

Restful factory for AngularJS. Used [Restify](https://github.com/IlanFrumer/Restify). Ported to ES6 and published to npm.

Downloads

25

Readme

Restify

Restful factory for AngularJS. Used Restify. Ported to ES6 and published to npm.

Install

  • npm install ng-restify

Dependencies

Example

# declare restify as a dependency of your application module
app = angular.module('yourModule',['restify'])

# create a service by injecting restify and using its factory function
# note: you should probably create one service for the whole api
#       and then pass it all over the place

app.factory 'API', ['restify',(restify)->

  # restify
  # gets a base url and a configuration block
  # returns a Restified Object

  restify '/api' , (config)->

    # add your endpoints
    config.add('/users/:id/images')
    config.add('/stores/:name/branches/:id')
    config.add('/stores/:name/products/:id')
    config.add('/stores/:name/images')
]


# inject your service and start playing

app.controller 'MyCtrl',['$scope', 'API', ($scope, API)->

  # GET /api/users
  API.users.$get().then (users)->
    $scope.users = users

  $scope.userImages = (user)->
    # provided that user.id == 123
    # GET /api/users/123/images
    user.images.$uget().then (images)->
      user.images = images

  $scope.create = (user)->
    # PUT /api/users
    $scope.users.$post(user)

  $scope.save = (user)->
    # provided that user.id == 123
    # PUT /api/users/123
    user.$put()

  $scope.changePassword = (user, password)->
    # provided that user.id == 123
    # PATCH /api/users/123
    user.$patch({password: password})

  $scope.remove (user)->
    user.$delete().then ()->
      $scope.users = _.without($scope.users,user)
]
View:
  <ul>
    <li ng-repeat="user in users">
      <input type="text" ng-model="user.name">
      <input type="text" ng-model="user.email">
      <button ng-click="save(user)">Save</button>
      <button ng-click="remove(user)">Remove</button>
      <button ng-click="getImages(user)">See Images</button>
      <ul>
        <li ng-repeat="image in user.images">
            <img src="{{image.src}}" alt="{{image.alt}}">
        </li>
      </ul>
    </li>
  </ul>

Restify Class

Own properties (All own properties are prefixed with $$)

Owned properties are ment to be used internally, don't mess with them!

  • $$url
  • $$route
  • $$parent
  • $$headers
  • $$requestInterceptor
  • $$responseInterceptor

Methods (All inherited methods are prefixed with $)

  • $get(): getting the response and restifying it
  • $uget(): getting the response without restifying it
  • $delete():
  • $post([data]): If data is not provided then this object is sent stripped from functions or Restified objects.
  • $patch([data]): If data is not provided then this object is sent stripped from functions or Restified objects.
  • $put([data]): If data is not provided then this object is sent stripped from functions or Restified objects.

Configuration methods(see below)

  • $setHeaders(headers)
  • $setResponseInterceptor(callback)
  • $setRequestInterceptor(callback)

Configartion

All restified object inherits configuration from its parent chain and may override it

# parent chain: api > users > user

users = api.users
user = users.$id(123)

api.$setHeaders({'X-AUTH-TOKEN': 123})
user.$get() # sends X-AUTH-TOKEN: 123

users.$setHeaders({'X-AUTH-TOKEN': 456})
user.$get() # sends X-AUTH-TOKEN: 456

api.$get() # still sends X-AUTH-TOKEN: 123

# note: $id creates a new restified object
sameUser = users.$id(123)
user !== sameUser # true

# note: every request data creates a new restified object
user.$get.then(sameUser)->
  user !== sameUser # true