private strip_object ($obj)
Strip the non-visible properties from an object. Returns it as an associative array.
public get__default ($id = false)
Handles getting a list of items via GET /resource
or a single item via GET /resource/ID
.
Usage:
GET /resource/ID
GET /resource
GET /resource?offset=30
public post__default ($id = false)
Handles creating a new item via POST /resource
.
Returns the newly created resource, which should
include its new ID value. Also handles updating
existing items via POST /resource/ID
.
Usage:
POST /resource
POST /resource/ID
Generates a RESTful CRUD (Create, Read, Update, Delete) interface for a given model, with control for enforcing limits, visibility of fields, and which fields can be updated through the REST API.
Usage:
Define your API library:
Connect it in a handler:
require_auth (user\Auth\HMAC::init ($this, $cache, 3600)); // Hand the request off to your new API $this->restful (new blog\API); ?>Your API should now be accessible at the following endpoint:
To version your API, simply save it into a subfolder with the version name, for example:
Will map to:
For easy JavaScript access, see
apps/admin/js/api.js
which provides a client-side wrapper around the built-in CRUD methods. Simply give it a name and an endpoint URL path.The various built-in methods include:
Also note that
CRUD
inherits fromRestful
, so you can add as many new methods to your API as you need.