Skip to content

Commit e6d03c0

Browse files
committed
Merge branch 'master' of https://github.com/iamblue/ngApi
2 parents abfc9b6 + 3da17bc commit e6d03c0

File tree

1 file changed

+69
-21
lines changed

1 file changed

+69
-21
lines changed

README.md

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ngApi
22
=========
33

44
An AngularJS module that makes your APIs working in the Angular Way.
5-
You only write html tag , `DON'T NEED TO` write too many Ajax by javascript.
5+
You only write html tag , `DON'T NEED TO` write too many Ajax by javascript in your angualr controller!!!!! lol
66

77
Example:
88

@@ -72,30 +72,66 @@ Init:
7272
angular.module('yourApp', ['ngapi'])
7373
```
7474

75-
Setting API url:
75+
### Setting API constant:
76+
77+
__For example :__
78+
79+
```javascript
80+
.constant('api', {
81+
url: { // must write it!
82+
routes: 'http://localhost:3000/youmeb/routes.json'
83+
},
84+
validate: { // If you have, write it.
85+
//Input your setting validate way
86+
},
87+
crypto: function(){}, // If you have, write it.
88+
cnonce: 'cnonce', // If you have, write it.
89+
})
90+
```
91+
92+
__Explain above api :__
93+
94+
`url`:
7695

7796
* For example: http://127.0.0.1:3000
7897

7998
```javascript
80-
.constant('apiurl','http://127.0.0.1:3000')
99+
.constant('api',{
100+
//....
101+
url: 'http://127.0.0.1:3000'
102+
})
81103
```
82104

83105
* If you have all of your api routes (json) from your api server, try that:
84106

85107
```javascript
86-
.constant('apiurl',{
87-
routes:'http://127.0.0.1:3000/youmeb/routes.json',
88-
//you can make many routes , ngapi will combine it to a scope.
108+
.constant('api',{
109+
//...
110+
url: {
111+
routes:'http://127.0.0.1:3000/youmeb/routes.json'
112+
//you can add many routes , ngapi will combine it to a scope.
113+
}
89114
});
90115
```
116+
==> more info: [see](https://github.com/iamblue/ngApi#ng-api-style-ng-api--dataapi)
117+
118+
`validate`:
91119

92-
## `ng-api` style: ng-api = "(data)(api)"
120+
==> more info: [see](https://github.com/iamblue/ngApi#expand)
93121

94-
1. data : (model_name : validate : validate_error_callback||.....)
122+
`crypto` && `cnonce`:
123+
124+
==> more info: [see](https://github.com/iamblue/ngApi#if-you-want-to-authentication-login-by-restful-architecture)
125+
126+
127+
128+
129+
### Setting `ng-api` style in yout HTML : ng-api = "(data)(api)"
130+
131+
1. data : (model_name : validate ||.....)
95132

96133
1. model_name
97134
2. validate
98-
3. validate_error_callback:
99135

100136
2. api:
101137

@@ -108,9 +144,12 @@ Setting API url:
108144
if you use:
109145

110146
```javascript
111-
.constant('apiurl',{
112-
routes:'http://127.0.0.1:3000/youmeb/routes.json',
113-
//you can make many routes , ngapi will combine it to a scope.
147+
.constant('api',{
148+
//...
149+
url: {
150+
routes:'http://127.0.0.1:3000/youmeb/routes.json'
151+
//you can add many routes , ngapi will combine it to a scope.
152+
}
114153
});
115154
```
116155
And the json content like that:
@@ -128,26 +167,29 @@ And the json content like that:
128167
You can use (routes.api.getnavs) , it will help you retreive `get` and `/api/getnavs` data.
129168

130169

131-
## success callback / error callback:
170+
## After sending api , it response success callback / error callback:
132171

133-
You can use `api-success` or `api-error` do it.
172+
You can use `api-success` or `api-error` to callback it.
134173

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

138177
```
139178

140179

141-
142180
Expand
143181
=======
144182

145183
### If you want to expand validate libery:
146184

147185
```javascript
148-
.constant('apivalidate',{
149-
date:function(v){
186+
.constant('api',{
187+
//....
188+
validate:{
189+
date: function(){
150190
// your new validate method
191+
}
192+
//....
151193
}
152194
});
153195
```
@@ -160,16 +202,22 @@ On a common REST-authentication architecture, we need browser make a Cnonce cons
160202
* Step1: Make a Cnonce :
161203

162204
```javascript
163-
.constant('apicnonce','cnonce') // 'cnonce' can include a function which will make a new cnonce code
205+
.constant('api',{
206+
//....
207+
cnonce:'cnonce',
208+
}) // 'cnonce' can include a function which will make a new cnonce code
164209
```
165210

166211
* Step2: Add a apicrypto algo:
167212

168213
```javascript
169-
.constant('apicrypto',function(){
170-
//your crypto algo, for example :sha1,md5 ... etc
214+
.constant('api',{
215+
//....
216+
cnonce: 'cnonce',
217+
crypto: function(){
218+
//your crypto algo, for example :sha1,md5 ... etc
219+
}
171220
})
172-
173221
```
174222

175223
###Reference:

0 commit comments

Comments
 (0)