rizeway/orem

Rizeway OREM is a Restful API Abstraction Layer. It is to Restful APIs what doctrine is for databases.

v1.0.0 2015-10-08 08:25 UTC

This package is not auto-updated.

Last update: 2024-04-07 04:17:45 UTC


README

Build Status

Rizeway OREM is a Restful API Abstraction Layer. It is to Restful APIs what doctrine is to databases.

Getting Started

Say you have the following JSON HTTP API to make CRUD on an object named "status"

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.

2- Create a mapping file in this folder. The mapping file sould be named status.orem.yml and will look like this.

class: MyNamespace/Status
fields:
    id:
        primaryKey: true
    message:
        type: string
    author:
        type: string
    count_likes
        type: integer    

3- Create a simple entity class

<?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

$factory = new \Rizeway\OREM\Config\Factory($directory, $apiBaseUrl);
$manager = $factory->getManager();

5- How to use the manager to make api calls

$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

{
    "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

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

./bin/atoum --test-all