wp-api-angular
Angular >=7 services for WordPress >= 4.7 Rest API
Fork of buggy1985/wp-api-angular -> wordpress-clients/wp-api-angular
================
Ng services to consume WP-API v2
If you want to use AngularJS v1, here is the latest version: v2.0.0-rc3. npm i wp-api-angularjs@v2.0.0-rc3
Installation
npm install wp-api-angular
TypeScript
Nothing special if you use TS
UMD
UMD files are available wp-api-angular.umd.js
and wp-api-angular.umd.min.js
, the Live Demo uses them with systemJS
Bootstrap
An exported function WpApiLoaderFactory
is mandatory to be used with AoT compilation or Ionic 2.
{ return 'http://YOUR_DOMAIN/wp-json/' /* namespace is optional, default: '/wp/v2' */;} @
API
Every method return an Obervable. If you want to get a Promise you will need to add the rxjs toPromise
operator:
{ thiswpApiPosts }
RequestOptionsArgs
Every request can have an optional httpOptions
object.
This is where you can add query string to your request or change the headers (see below).
import { HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Max-Age': '1728000',
'Access-Control-Allow-Headers': 'Content-Type, Content-Range, Content-Disposition, Content-Description'
'Access-Control-Allow-Methods': 'DELETE, HEAD, GET, OPTIONS, POST, PUT'
})
};
wpApiPosts.getList(httpOptions);
WpApiPosts
getListoptions?: object: Observable<object>; getpostId, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updatepostId, body: any, options?: object: Observable<object>; deletepostId, options?: object: Observable<object>; getMetaListpostId, options?: object: Observable<object>; getMetapostId, metaId, options?: object: Observable<object>; getRevisionListpostId, options?: object: Observable<object>; getRevisionpostId, revisionId, options?: object: Observable<object>; getCategoryListpostId, options?: object: Observable<object>; getCategorypostId, categoryId, options?: object: Observable<object>; getTagListpostId, options?: object: Observable<object>; getTagpostId, tagId, options?: object: Observable<object>;
WpApiPages
getListoptions?: object: Observable<object>; getpageId: number, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updatepageId: number, body: any, options?: object: Observable<object>; delete
WpApiComments
getListoptions?: object: Observable<object>; getcommentId: number, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updatecommentId: number, body: any, options?: object: Observable<object>; delete
WpApiTypes
getListoptions?: object: Observable<object>; getpostType: string, options?: object: Observable<object>;
WpApiMedia
getListoptions?: object: Observable<object>; getmediaId: number, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updatemediaId: number, body: any, options?: object: Observable<object>; delete
WpApiUsers
getListoptions?: object: Observable<object>; meoptions?: object: Observable<object>; getuserId: number, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updateuserId: number, body: any, options?: object: Observable<object>; delete
WpApiTaxonomies
getListoptions?: object: Observable<object>; gettaxonomiesType: string, options?: object: Observable<object>;
WpApiStatuses
getListoptions?: object: Observable<object>; getstatusesName: string, options?: object: Observable<object>;
WpApiTerms
taxonomiesType
can be tags
, categories
and more.
getListtaxonomiesType: string, options?: object: Observable<object>; gettaxonomiesType: string, termId: number, options?: object: Observable<object>; createtaxonomiesType: string, body: any, options?: object: Observable<object>; updatetaxonomiesType: string, termId: number, body: any, options?: object: Observable<object>; delete
WpApiCustom
getListoptions?: object: Observable<object>; getcustomId: number, options?: object: Observable<object>; createbody: any, options?: object: Observable<object>; updatecustomId: number, body: any, options?: object: Observable<object>; delete
Authentication
TO BE DEFINED
Contribute
npm install # Open two terminals # and run watch to build on the lib files changes npm run watch # in the other terminal run following to build the test page npm start
Open http://localhost:8080