forked from omeka/omeka-s
-
Notifications
You must be signed in to change notification settings - Fork 0
jimsafley edited this page Jan 28, 2015
·
8 revisions
Omeka S executes most operations through API calls. Let's say you want to get item #100 from the database:
// Compose the request object
$request = new Request(Request::READ, 'item');
$request->setId(100);
// Execute the request
$response = $apiManager->execute($request);
// Get the representation
$item = $response->getContent();
// The above could be written more concisely (recommended usage)
$item = $apiManager->read('item', 100)->getContent();
// Do something with the representation.
echo $item->jsonSerialize();
For HTTP clients we provide a RESTful interface on top of the API. An HTTP request for the above example looks something like this:
http://your-domain.com/api/items/100
The HTTP response will be formatted in JSON-LD, a method of transporting Linked Data using JSON. Example JSON-LD
Resources are registered in configuration and implemented with adapter and representation classes. The adapter is responsible for performing SCRUD operations on a resource. A representation is a read-only, serializable object that represents a resource.
Search for resources by criteria.
$response = $apiManager->search('your_resource', array('foo' => 'bar'));
GET /api/your_resource?foo=bar
Create a resource.
$response = $apiManager->create('your_resource', array('foo' => 'bar'));
POST /api/your_resource
Content-Type: application/json
{"foo":"bar"}
Create resources in batch.
$response = $apiManager->batchCreate('your_resource', array(
array('foo' => 'bar'),
array('baz' => 'bat'),
));
Get one resource.
$response = $apiManager->read('your_resource', 100);
GET /api/your_resource/100
Update a resource.
$response = $apiManager->update('your_resource', 100, array('foo' => 'bar'));
PUT /api/your_resource/100
Content-Type: application/json
{"foo":"bar"}
Delete a resource.
$response = $apiManager->delete('your_resource', 100);
DELETE /api/your_resource/100