定制 joeybeninghove/json-api-wp-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

joeybeninghove/json-api-wp-client

Composer 安装命令:

composer require joeybeninghove/json-api-wp-client

包简介

WordPress client library for consuming JSON APIs following the 1.0 spec at jsonapi.org

README 文档

README

This library is an opinionated, resource-based JSON API client for WordPress that strives to adhere to the offical JSON API 1.0 spec.

Requirements

  • WordPress

Usage

Define a resource

  • base_url is specified as the root URL used when interacting with the API.
  • type is the JSON API type for the current resource
class Invoice extends Json_Api_Wp_Resource
{
    public function __construct()
    {
        parent::__construct(
            "https://api.site.com/v1/", // base URL
            "invoices" // type
        )
    }
}

Set up HTTP Authentication

The username is required, but the password is optional and defaults to blank.

Json_Api_Wp_Resource::auth( "jdoe", "secret" );

API Key example

If you're using a typical API key over HTTP Authentication, here is an example of using a base class to abstract that away.

class Base extends Json_Api_Wp_Resource
{
    public function __construct( $type )
    {
        parent::__construct( "http://api.site.come/v1/", $type );
    }

    public static function set_api_key( $api_key )
    {
        parent::auth( $apiKey );
    }
}

class Invoice extends Base
{
    public function __construct()
    {
        parent::__construct( "invoices" );
    }
}

Base::set_api_key( "some secret key" );
$invoices = Invoice::get_all();

Create a resource

$invoice = Invoice::create([
    "description" => "T-Shirt",
    "total" => 10.95
]);

Update a resource

This library does not yet support updating of resources because of the lack of PATCH support in the WordPress HTTP library.

Get a single resource

$invoice = Invoice::get_one( "invoice_123" );

Get all resources

$invoices = Invoice::get_all();

Delete a resource

This library does not yet support updating of resources because of the lack of DELETE support in the WordPress HTTP library.

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固