2017 © Pedro Peláez
 

library json-api-wp-client

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

image

joeybeninghove/json-api-wp-client

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

  • Tuesday, February 7, 2017
  • by joeybeninghove
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

JSON API WordPress Client

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

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., (*2)

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., (*3)

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., (*4)

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., (*5)

The Versions

07/02 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Joey Beninghove

wordpress api json

07/02 2017

0.1.1

0.1.1.0

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

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Joey Beninghove

wordpress api json

07/02 2017

0.1

0.1.0.0

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

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Joey Beninghove

wordpress api json