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 in your angualr controller!!!!! lol
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...):
-
loginnamemeans it will retreive loginname (ng-model's data), andstringmeans 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.nospaceIf you want to expand validate methods, see
-
loginname,loginemail,loginpasswordwill be sent by ajax data , look like following:
data:{
loginname:loginname,
loginemail:loginemail,
loginpassword:loginpassword
}- More infomations: see
- (post:/api/login):
postmeans it will post to/api/login.
bower install ngapiAdd following into your Html <head>:
<script src="bower_components/ngapi/ngapi.js"></script>Init:
angular.module('yourApp', ['ngapi'])For example :
.constant('api', {
url: { // must write it!
routes: 'http://localhost:3000/youmeb/routes.json'
},
validate: { // If you have, write it.
//Input your setting validate way
},
crypto: function(){}, // If you have, write it.
cnonce: 'cnonce', // If you have, write it.
})Explain above api :
url:
- For example: http://127.0.0.1:3000
.constant('api',{
//....
url: 'http://127.0.0.1:3000'
})- If you have all of your api routes (json) from your api server, try that:
.constant('api',{
//...
url: {
routes:'http://127.0.0.1:3000/youmeb/routes.json'
//you can add many routes , ngapi will combine it to a scope.
}
});==> more info: see
validate:
==> more info: see
crypto && cnonce:
==> more info: see
-
data : (model_name : validate ||.....)
- model_name
- validate
-
api:
-
(request:path): request method:
post,get,restfulloginFor example: post:/api/getnavs , get:/api/getnavs , restfullogin:/api/rest-auth/login ...etc
-
(routes.api.getnavs):
if you use:
.constant('api',{
//...
url: {
routes:'http://127.0.0.1:3000/youmeb/routes.json'
//you can add 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.
You can use api-success or api-error to callback 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>
.constant('api',{
//....
validate:{
date: function(){
// your new validate method
}
//....
}
});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('api',{
//....
cnonce:'cnonce',
}) // 'cnonce' can include a function which will make a new cnonce code - Step2: Add a apicrypto algo:
.constant('api',{
//....
cnonce: 'cnonce',
crypto: function(){
//your crypto algo, for example :sha1,md5 ... etc
}
})###Reference:
About REST-Authentication, I sugguest you to read following paper: