wp-api-angularjs

3.0.0-alpha2 • Public • Published

wp-api-angularjs

Angular2 services to consume WP-API v2 (< 2.5kb gziped)

If you want to use AngularJS v1, here is the latest version: v2.0.0-rc3

Installation

npm install wp-api-angularjs

Bootstrap

import {
  WPAPI_PROVIDERS,
  defaultWpApi
} from 'wp-api-angularjs';
 
import {App} from './app';
 
bootstrap(App, [
  WPAPI_PROVIDERS,
  defaultWpApi({
    baseUrl: "http://YOUR_DOMAIN/wp-json/",
    namespace: '/wp/v2' // (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:

import 'rxjs/add/operator/toPromise';
 
class Test {
  constructor(private wpApiPosts: WpApiPosts) {
    this.wpApiPosts.getList()
      .toPromise()
      .then(response => response.json())
      .then(body => {})
      .catch(error => {})
  }
}
 

RequestOptionsArgs

Every request can have an optional RequestOptionsArgs object.

class RequestOptionsArgs {
  url : string
  method : string|RequestMethod
  search : string|URLSearchParams
  headers : Headers
  body : any
  withCredentials : boolean
}

This is where you can add query string to your request or change the headers.

WpApiPosts

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(postId, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(postId, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(postId, options?: RequestOptionsArgs)Observable<Response>;
  getMetaList(postId, options?: RequestOptionsArgs)Observable<Response>;
  getMeta(postId, metaId, options?: RequestOptionsArgs)Observable<Response>;
  getRevisionList(postId, options?: RequestOptionsArgs)Observable<Response>;
  getRevision(postId, revisionId, options?: RequestOptionsArgs)Observable<Response>;
  getCategoryList(postId, options?: RequestOptionsArgs)Observable<Response>;
  getCategory(postId, categoryId, options?: RequestOptionsArgs)Observable<Response>;
  getTagList(postId, options?: RequestOptionsArgs)Observable<Response>;
  getTag(postId, tagId, options?: RequestOptionsArgs)Observable<Response>;

WpApiPages

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(pageIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(pageIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
  getMetaList(pageId: number, options?: RequestOptionsArgs)Observable<Response>;
  getMeta(pageId: number, metaId: number, options?: RequestOptionsArgs)Observable<Response>;
  getRevisionList(pageId: number, options?: RequestOptionsArgs)Observable<Response>;
  getRevision(pageId: number, revisionId: number, options?: RequestOptionsArgs)Observable<Response>;

WpApiComments

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(commentIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(commentIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(commentId: number, options?: RequestOptionsArgs): Observable<Response>;

WpApiTypes

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(postTypestring, options?: RequestOptionsArgs)Observable<Response>;

WpApiMedia

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(mediaIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(mediaIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(mediaId: number, options?: RequestOptionsArgs): Observable<Response>;

WpApiUsers

  getList(options?: RequestOptionsArgs)Observable<Response>;
  me(options?: RequestOptionsArgs)Observable<Response>;
  get(userIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(userIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(userId: number, options?: RequestOptionsArgs): Observable<Response>;

WpApiTaxonomies

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(taxonomiesTypestring, options?: RequestOptionsArgs)Observable<Response>;

WpApiStatuses

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(statusesNamestring, options?: RequestOptionsArgs)Observable<Response>;

WpApiTerms

taxonomiesType can be tags, categories and more.

  getList(taxonomiesTypestring, options?: RequestOptionsArgs)Observable<Response>;
  get(taxonomiesTypestring, termIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(taxonomiesTypestring, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(taxonomiesTypestring, termIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(taxonomiesType: string, termId: number, options?: RequestOptionsArgs): Observable<Response>;

WpApiCustom

  getList(options?: RequestOptionsArgs)Observable<Response>;
  get(customIdnumber, options?: RequestOptionsArgs)Observable<Response>;
  create(bodyany, options?: RequestOptionsArgs)Observable<Response>;
  update(customIdnumber, bodyany, options?: RequestOptionsArgs)Observable<Response>;
  delete(customId: number, options?: RequestOptionsArgs): Observable<Response>;

Authentication

TO BE DEFINED

Contribute

npm install
cp config.dist.json config.json
 
# 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 and the doc 
npm run devserver

Open http://localhost:8080

/wp-api-angularjs/

    Package Sidebar

    Install

    npm i wp-api-angularjs

    Weekly Downloads

    1

    Version

    3.0.0-alpha2

    License

    MIT

    Last publish

    Collaborators

    • shprink