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
or a single item via
GET /resource/ID GET /resource GET /resource?offset=30
public post__default ($id = false)
Handles creating a new item via
Returns the newly created resource, which should
include its new ID value. Also handles updating
existing items via
POST /resource POST /resource/ID
public delete__default ($id)
Delete an object via
Returns the deleted object data on success.
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.
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:
apps/admin/js/api.jswhich 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
Restful, so you can add as many new methods to your API as you need.