Skip to content

Commit 7a2e4e1

Browse files
committed
bundle before release
1 parent 698ce7c commit 7a2e4e1

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
wp-api-angularjs
22
================
33

4-
Angular2 services to consume [WP-API v2](http://v2.wp-api.org/)
4+
Angular2 services to consume [WP-API v2](http://v2.wp-api.org/) (< 2.5kb gziped)
55

66
If you want to use AngularJS v1, here is the latest version: [v2.0.0-rc3](https://github.com/shprink/wp-api-angularjs/tree/v2.0.0-rc3)
77

@@ -53,13 +53,31 @@ class Test {
5353
constructor(private wpApiPosts: WpApiPosts) {
5454
this.wpApiPosts.getList()
5555
.toPromise()
56-
.then((response) => {})
57-
.catch((error) => {})
56+
.then(response => response.json())
57+
.then(body => {})
58+
.catch(error => {})
5859
}
5960
}
6061

6162
```
6263

64+
### RequestOptionsArgs
65+
66+
Every request can have an optional [`RequestOptionsArgs`](https://angular.io/docs/ts/latest/api/http/index/RequestOptionsArgs-interface.html) object.
67+
68+
```js
69+
class RequestOptionsArgs {
70+
url : string
71+
method : string|RequestMethod
72+
search : string|URLSearchParams
73+
headers : Headers
74+
body : any
75+
withCredentials : boolean
76+
}
77+
```
78+
79+
This is where you can add query string to your request or change the headers.
80+
6381
### WpApiPosts
6482

6583
```ts

demo/app.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export class App {
7373
this.request(wpApiCustom.getInstance(customType), serviceApi, serviceName);
7474
});
7575
} else {
76-
console.log('serviceName', serviceName)
7776
this.request(this[serviceName], serviceApi, serviceName);
7877
}
7978
}
@@ -83,8 +82,17 @@ export class App {
8382
Object.keys(serviceApi).map((method) => {
8483
let parameters = serviceApi[method];
8584
service[method].apply(service, parameters).toPromise()
86-
.then(() => this.requests.push({ serviceName: serviceName.slice(5), method, success: true }))
87-
.catch(() => this.requests.push({ serviceName: serviceName.slice(5), method, success: false }))
85+
.then(response => response.json())
86+
.then(body => {
87+
console.groupCollapsed(serviceName, method, JSON.stringify(parameters));
88+
console.log(body);
89+
console.groupEnd()
90+
this.requests.push({ serviceName: serviceName.slice(5), method, success: true })
91+
})
92+
.catch(error => {
93+
console.error(serviceName, method, error.json());
94+
this.requests.push({ serviceName: serviceName.slice(5), method, success: false })
95+
});
8896
});
8997
}
9098
}

dist/wp-api-angularjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/wp-api-angularjs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/interfaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export interface IWpApiTerms {
9292
delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable<Response>;
9393
}
9494

95-
9695
export interface IWpApiCustom {
9796
getList(options?: RequestOptionsArgs): Observable<Response>;
9897
get(customId: number, options?: RequestOptionsArgs): Observable<Response>;

0 commit comments

Comments
 (0)