当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

wp-api-angular

授权协议 View license
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 范侯林
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

wp-api-angular

Angular >=2 services for WordPress >= 4.7 Rest API

================

Angular2 services to consume WP-API v2

Live Demo

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 -g typings
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.

import { Http } from '@angular/http';
import { 
  WpApiModule,
  WpApiLoader,
  WpApiStaticLoader
} from 'wp-api-angular'

export function WpApiLoaderFactory(http: Http) {
  return new WpApiStaticLoader(http, 'http://YOUR_DOMAIN/wp-json/', /* namespace is optional, default: '/wp/v2' */);
}

@NgModule({
  imports: [
    BrowserModule,
    WpApiModule.forRoot({
      provide: WpApiLoader,
      useFactory: (WpApiLoaderFactory),
      deps: [Http]
    })
  ],
  bootstrap: [App]
})
export class AppModule { }

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 (see below).

import { Headers } from '@angular/http';

const headers = new Headers({
  '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({ headers });

WpApiPosts

getList(options?: RequestOptionsArgs): Observable<Response>;
  get(postId, options?: RequestOptionsArgs): Observable<Response>;
  create(body: any, options?: RequestOptionsArgs): Observable<Response>;
  update(postId, body: any, 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(pageId: number, options?: RequestOptionsArgs): Observable<Response>;
  create(body: any, options?: RequestOptionsArgs): Observable<Response>;
  update(pageId: number, body: any, 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(commentId: number, options?: RequestOptionsArgs): Observable<Response>;
  create(body: any, options?: RequestOptionsArgs): Observable<Response>;
  update(commentId: number, body: any, options?: RequestOptionsArgs): Observable<Response>;
  delete(commentId: number, options?: RequestOptionsArgs): Observable<Response>;

WpApiTypes

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

WpApiMedia

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

WpApiUsers

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

WpApiTaxonomies

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

WpApiStatuses

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

WpApiTerms

taxonomiesType can be tags, categories and more.

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

WpApiCustom

getList(options?: RequestOptionsArgs): Observable<Response>;
  get(customId: number, options?: RequestOptionsArgs): Observable<Response>;
  create(body: any, options?: RequestOptionsArgs): Observable<Response>;
  update(customId: number, body: any, 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
npm start

Open http://localhost:8080

  • 本文由Vildan Softic进行同行评审。 感谢所有SitePoint的同行评审人员使SitePoint内容达到最佳状态! 作为Web开发人员,如果您不能错过任何内容,那就是Angular 2 。 它是对Google流行的JavaScript框架的完全重写,并且出于所有正确的原因,它一直是新闻。 与以前的版本相比,它提供了一些重大改进,因此我们今天选择它来构建一些漂亮的图表。 对于图表,我们将

  • 配置: Nginx: conf目录下nginx.conf配置文件。 第44行改为:root   D:/wwwroot/www; 第45行改为:index  index.html index.htm index.php;  加了PHP文件支持。 第65至71行改为: (改为)location ~ \.php$ { root        D:/wwwroot/www; fastcgi_pass 12

  • carla.Actor CARLA将actors定义为在模拟器起作用或可以移动的任何事物。其中包括:行人(pedestrians),车辆( vehicles),传感器(sensors)和交通标志(将交通灯视为其中的一部分)。 Actor通过carla.World在模拟器中生成,并需要创建carla.ActorBlueprint。这些蓝图属于CARLA提供的库,请在here找到有关它们的更多信息。

 相关资料
  • 我想使用这个插件的可湿性粉剂RestAPI认证:https://github.com/Tmeister/wp-api-jwt-auth 我在POST:http://localhost/wp_rest/wp-json/jwt-auth/v1/token上获得带有此请求的令牌 但是我无法执行对post mehod的请求:localhost/wp_rest/wp-json/wp/v2/posts 我得到

  • 我使用以下插件从WordPress REST API获取JSON数据: 高级自定义字段PRO WP REST API ACF to REST API 我创建了一个名为“自定义导航”的自定义帖子类型。我有一个自定义字段组(通过ACF ),称为“自定义导航项目”,它只在文章类型是自定义导航时应用。该组中的字段称为“图像”和“标题”,我无法获得它们的值。 这是我为ACF to REST API插件设置菜

  • 我正在尝试使用wp rest api返回一个博客帖子列表,包括标题、摘录和特色图片。使用下面的方法,我可以返回标题和摘录,但特征图像会导致致命错误:无法将stdClass类型的对象用作数组。 有人能告诉我我做错了什么吗?

  • 几个月来,我一直在使用Wordpress REST插件WP-API进行本地开发,同时使用XAMPP进行本地开发。我最近将我的站点迁移到EC2实例,一切正常,除了我现在在尝试访问API上的任何endpoint时都会收到带有以下消息的404: 在此服务器上找不到请求的URL/wordpress/wp.json/ 使用以下结构在浏览器中导航到特定帖子时工作正常。 以下是关于我的设置的一些细节: Word

  • 当我从此endpoint提取数据时,我得到一个JSON对象。 当我添加_embed参数时,< code > http://blog . local/WP-JSON/WP/v2/posts?页面=1 根据Wordpress文档,当您传递参数时,您应该获得响应中包含的额外有用数据 - 这里 我刚收到一张真实的JPG图片。 有没有人见过这种情况,或者知道可能是什么问题?我不得不求助于添加自定义endpo

  • 比较高级, 比较漂亮也比较有用的一个反垃圾留言插言. 比较著名的reCAPTCHA为Wordpress提供. 但个人觉得太干扰用户了, 尤其是那个验证码, 留个言还要考验用户的视力和英文书法识别能力. 有够累