Skip to content

evanwilliamsconsulting/rapl

 
 

Repository files navigation

What is RAPL?

RAPL (RESTful API Persistence Layer) is a RESTful variant of Doctrine's ORM. It implements the same interfaces, but allows you to store and retrieve entities from a remote (RESTful) API instead of from the database.

Why use RAPL?

  • RAPL abstracts the REST architecture, the HTTP protocol and the serialization of objects for you. All you have to do is to create your entity classes and to map them to the API (using mapping configuration).
  • If you are maintaining an API and you want to provide a client library for it, you can simply build it on top of RAPL.

Code Quality

Build Status Coverage Status Code Quality

Requirements

RAPL requires PHP 5.4 or higher.

Installation

RAPL is on Packagist and can be installed using Composer:

composer require rapl/rapl

This will add RAPL to the dependency list of your main project's composer.json.

Setting up

<?php

require_once 'vendor/autoload.php';

use RAPL\RAPL\Configuration;
use RAPL\RAPL\Connection\Connection;
use RAPL\RAPL\EntityManager;
use RAPL\RAPL\Mapping\Driver\YamlDriver;
use RAPL\RAPL\Routing\Router;

$connection = Connection::create('http://example.com/api/');

$configuration = new Configuration();
$paths         = array(__DIR__ . '/config');
$driver        = new YamlDriver($paths, '.rapl.yml');
$configuration->setMetadataDriver($driver);

$router = new Router();

$manager = new EntityManager($connection, $configuration, $router);

Usage

Once you have set everything up correctly, you can start using RAPL. This will feel very familiar if you have worked with Doctrine before.

$repository = $manager->getRepository('Your\Entity\Class');

// Get entity with id 3
$entity = $repository->find(3);

// Or get all of them
$entities = $repository->findAll();

About

Doctrine-based EntityManager for REST APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%