User Tools

Site Tools


api_class

This is an old revision of the document!


Api Class

The Api class exposes any Datarecord object in a RESTful API interface. This is extremely simple to setup:

$api_endpoint = new Api(array('CLASSES_TO_INCLUDE'));
$api_endpoint->handle();

The endpoint extends itself from the script containing the code, and have the following path /instance_id/object_name/object_id/

So if you expose a class ExampleClass in an instance with ID 2, in a file here https://www.example.com/endpoint.php then you can get all the objects by calling this URL:

https://www.example.com/endpoint.php/2/exampleclass

If you want to retrieve the object with ID 24, then call the URL:

https://www.example.com/endpoint.php/2/exampleclass/24

To update the object, just POST to the same URL and to create a new object POST to the general URL above. One does not have to POST a complete object. Only the fields mentioned in the POST will be updated. The other fields will be left untouched. POST data should consist of a JSON-object similar to the one received when querying the API.

To delete an object make a call to DELETE

The API makes heavy use of the following functions in Datarecord to ensure proper operation:

  • canAccess()
  • canCreate()
  • canDelete()
  • canEdit()
  • validateObject()

…so be sure that those are implemented properly.

api_class.1576794242.txt.gz · Last modified: 2019/12/19 22:24 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki