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

ngapi

v0.1.8

Published

An AngularJS module that makes your APIs working in the Angular Way.

Downloads

1

Readme

ngApi

An AngularJS module that makes your APIs working in the Angular Way. You only write html tag , DON'T NEED TO write too many Ajax by javascript.

Example:

<input type="" ng-model="loginname"/>
<input type="" ng-model="loginemail"/>
<input type="" ng-model="loginpassword"/>

<a ng-api="(loginname:string||loginemail:email||loginpassword:nospace)(post:/api/login)" api-success="if you have or not" api-error="if you have or not">send</a>

##Description

  • (loginname:string...):
  1. loginname means it will retreive loginname (ng-model's data), and string means you will validate loginname (ng-model's data) whether be a string.

    In this module, we have four validate methods initailly:

     1.email 
     2.number 
     3.string 
     4.nospace
        

    If you want to expand validate methods, see

  2. loginname, loginemail , loginpassword will be sent by ajax data , look like following:

    data:{
        loginname:loginname,
        loginemail:loginemail,
        loginpassword:loginpassword
    }
  1. More infomations: see
  • (post:/api/login): post means it will post to /api/login.

Install

bower install ngapi

Add following into your Html <head>:

<script src="bower_components/ngapi/ngapi.js"></script>

Usage

Require ngapi and Inject the Services

Init:

angular.module('yourApp', ['ngapi'])

Setting API url:

  • For example: http://127.0.0.1:3000
  .constant('apiurl','http://127.0.0.1:3000')
  • If you have all of your api routes (json) from your api server, try that:
.constant('apiurl',{
  routes:'http://127.0.0.1:3000/youmeb/routes.json',
  //you can make many routes , ngapi will combine it to a scope.
});

ng-api style: ng-api = "(data)(api)"

  1. data : (model_name : validate : validate_error_callback||.....)

    1. model_name
    2. validate
    3. validate_error_callback:
  2. api:

  • (request:path): request method: post , get , restfullogin

    For example: post:/api/getnavs , get:/api/getnavs , restfullogin:/api/rest-auth/login ...etc

  • (routes.api.getnavs):

    if you use:

.constant('apiurl',{
  routes:'http://127.0.0.1:3000/youmeb/routes.json',
  //you can make many routes , ngapi will combine it to a scope.
});

And the json content like that:

{
    api.getnavs: {
        path: "/api/getnavs",
        methods: [
            "get"
        ]
    }
}

You can use (routes.api.getnavs) , it will help you retreive get and /api/getnavs data.

success callback / error callback:

You can use api-success or api-error do it.

<a ng-api="(loginname:string||loginemail:email||loginpassword:nospace)(post:/api/login)" api-success="your scope function" api-error="your scope function">send</a>
    

Expand

If you want to expand validate libery:

.constant('apivalidate',{
    date:function(v){
        // your new validate method
    }
});

If you want to authentication login by RESTful architecture

On a common REST-authentication architecture, we need browser make a Cnonce constant and crypo your "password code"+snonce( nonce form server)+c_nonce and send it back your server.

  • Step1: Make a Cnonce :
.constant('apicnonce','cnonce')  // 'cnonce' can include a function which will make a new cnonce code 
  • Step2: Add a apicrypto algo:
.constant('apicrypto',function(){
    //your crypto algo, for example :sha1,md5 ... etc
})

###Reference:

About REST-Authentication, I sugguest you to read following paper: