Rizeway OREM
, (*1)
Rizeway OREM is a Restful API Abstraction Layer. It is to Restful APIs what doctrine is to databases., (*2)
Getting Started
Say you have the following JSON HTTP API to make CRUD on an object named "status", (*3)
GET /status # Return a list of statuses
GET /status/1 # Return the status of id 1
POST /status # Create a status (the body of the request contain the hash of the status)
PUT /status/1 # Update the status of id 1 (the body of the request contain the hash of the status)
DELETE /status/1 # Delete the status of id 1
1- Create a folder to store your mappings., (*4)
2- Create a mapping file in this folder. The mapping file sould be named status.orem.yml and will look like this., (*5)
class: MyNamespace/Status
fields:
id:
primaryKey: true
message:
type: string
author:
type: string
count_likes
type: integer
3- Create a simple entity class, (*6)
<?php
namespace MyNamespace
class Status
{
protected $id;
protected $message;
protected $author;
protected $count_likes = 0;
public function getId()
{
return $this->id;
}
public function getMessage()
{
return $this->message;
}
public function setMessage($message)
{
$this->message = $message;
}
public function getAuthor()
{
return $this->author;
}
public function setAuthor($author)
{
$this->author = $author;
}
public function getCountLikes()
{
return $this->count_likes;
}
public function addLike()
{
$this->count_likes++;
}
}
4- Get an OREM Manager, (*7)
$factory = new \Rizeway\OREM\Config\Factory($directory, $apiBaseUrl);
$manager = $factory->getManager();
5- How to use the manager to make api calls, (*8)
$status = new \MyNamespace\Status();
$status->setMessage('my message');
$status->setAuthor('author');
$manager->persist($status); // Call POST API
$status->addLike();
$manager->update($status); // Call PUT API
$manager->remove($status); // Call DELETE API
$statuses = $manager->getRepository('status')->findAll(); // Call GET api and return an array of \MyNamespace\Status
$status = $manager->getRepository('status')->find(1); // GET api with primary key, return an object \MyNamespace\Status
Installation
Install using composer, (*9)
{
"require": {
"rizeway/orem": "0.1.*@dev"
}
}
Roadmap
- Url Customisation
- Handling HasMany and HasOne lazy loading
- Handling Cascade Delete And Options to disable Cascade update
- Custom api functions
- More Field Types
- Extra parameters in URL (like CAS ticket or Other auth token)
Contribute
Install the dependencies using composer and you're ready to go, (*10)
git clone https://github.com/youknowriad/OREM.git && cd OREM
curl -s http://getcomposer.org/installer | php
./composer.phar install --dev
Tests
OREM is tested using atoum, (*11)
./bin/atoum --test-all