PHPackages                             nojimage/cakephp-rest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. nojimage/cakephp-rest

ActiveCakephp-plugin[API Development](/categories/api)

nojimage/cakephp-rest
=====================

A CakePHP Plugin containing a DataSource for interacting with ReSTful web services.

2.0.3(13y ago)137165MITPHPPHP &gt;=5.2.8

Since Feb 9Pushed 11y ago5 watchersCompare

[ Source](https://github.com/nojimage/CakePHP-ReST-DataSource-Plugin)[ Packagist](https://packagist.org/packages/nojimage/cakephp-rest)[ Docs](https://github.com/nojimage/CakePHP-ReST-DataSource-Plugin)[ RSS](/packages/nojimage-cakephp-rest/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

CakePHP ReST DataSource Plugin
==============================

[](#cakephp-rest-datasource-plugin)

A CakePHP Plugin containing a DataSource for interarcting with ReSTful web services.

[![Build Status](https://camo.githubusercontent.com/7deb3f08e382a688b66d052646266ead3c05d2df3024952b337b855f59554f5e/68747470733a2f2f7472617669732d63692e6f72672f6e6f6a696d6167652f43616b655048502d526553542d44617461536f757263652d506c7567696e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/nojimage/CakePHP-ReST-DataSource-Plugin)

Requirements
------------

[](#requirements)

- PHP 5.2.8 upper
- CakePHP 2.x.

Installation
------------

[](#installation)

### Get plugin

[](#get-plugin)

using composer

```
composer require "nojimage/cakephp-rest":"2.*"

```

or, use git submodule

```
git submodule add https://github.com/nojimage/CakePHP-ReST-DataSource-Plugin.git app/Plugin/Rest

```

### Setup APP/Config/bootstrap.php

[](#setup-appconfigbootstrapphp)

```
CakePlugin::load('Rest');

```

How it works
------------

[](#how-it-works)

- The DataSource issues HTTP requests through CakePHP's HttpSocket class (default) or your own implementation/extension, e.g. an OAuth enabled HttpSocket [http://github.com/neilcrookes/http\_socket\_oauth](http://github.com/neilcrookes/http_socket_oauth), passed in in the constructor.
- It implements create, read, update and delete methods, which are called by Model::save(), Model::find() and Model::delete(). These methods expect your Model object to have a request property in the format defined in HttpSocket::request and add the appropriate HTTP verbs into the array if not already set, e.g. POST, GET, PUT, DELETE.
- These methods call the public RestSource::request() method passing it an instance of your model object, but you can also access it directly, passing an object with a request property, or an arrayin the format defined in HttpSocket::request or a string which is a URI.
- The raw response from the HttpSocket::request() is converted into an array, according to the response's content-type header (XML and JSON currently supported), and the result returned on success (determined by 2xx HTTP response code) or boolean false is returned on failure.
- In addition, if the argument to the request() method was an object, the result is also added to a response property of the object, and if the request failed, and the object has an onError() method, that method will be triggered.

Direct Usage
------------

[](#direct-usage)

1. In APP/Config/database.php, append to the datasource definition.

    /\*\*

    - RestSource
    -
    - @var array \*/ public $rest = array( 'datasource' =&gt; 'Rest.RestSource', 'database' =&gt; false, );
2. Create a model for each thing on web service you want to interact with. For example create a TwitterStatus model
3. Ensure your model uses this datasource by setting it in the $useDbConfig property, e.g.

    public $useDbConfig = 'rest';
4. Create a method in you model that corresponds to a function you can perform through the web service. E.g.

    ```
    public function save($data = null, $validate = true, $fieldList = array()) {
      $this->request = array(
        'uri' => array(
          'host' => 'twitter.com',
          'path' => 'statuses/update.json'
        ),
        'body' => array(
          'status' => $data['TwitterStatus']['text']
        )
      );
      return parent::save($data, $validate, $fieldList);
    }

    ```
5. Anywhere in your application, call:

    ```
    $result = ClassRegistry::init('TwitterStatus')->save(array('TwitterStatus' => array('text' => 'Hello World!')));

    ```

N.B. This example is purely representative and does not include authentication for example, but demonstrate the general idea.

Other Uses
----------

[](#other-uses)

I abstracted this functionality out of a lot of other datasources I was writing and I use this extensively as a base data source which I extend for each web service I need, handling the specifics of each of those web services, such as Authentication, in those classes, by overloading each of the public methods in the Rest datasource as required.

For example, you can create a TwitterSource which extends RestSource and overload the constructor to pass in an instance of my [HttpSocketOauth extension to CakePHP's HttpSocket](http://www.neilcrookes.com/2010/04/12/cakephp-oauth-extension-to-httpsocket) class, and the request() method, adding in the common request params such as the host key and '.json' on the end of the path key, and the specific authentication params, then just call parent::request() to handle the issuing of the request and parsing of the response.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Total

3

Last Release

4803d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a3fe494e51e33958f5c8079669fd036dfee4c2e6b11f85f2249ba36c371986e3?d=identicon)[nojimage](/maintainers/nojimage)

---

Top Contributors

[![nojimage](https://avatars.githubusercontent.com/u/100564?v=4)](https://github.com/nojimage "nojimage (26 commits)")

---

Tags

cakephpdatasource

### Embed Badge

![Health badge](/badges/nojimage-cakephp-rest/health.svg)

```
[![Health](https://phpackages.com/badges/nojimage-cakephp-rest/health.svg)](https://phpackages.com/packages/nojimage-cakephp-rest)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.6k10](/packages/helsingborg-stad-municipio)[october/rain

October Rain Library

1601.7M99](/packages/october-rain)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[mediawiki/maps

Adds various mapping features to MediaWiki

85155.1k3](/packages/mediawiki-maps)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

19256.6k4](/packages/civicrm-civicrm-drupal-8)[altis/core

Core module for Altis

19233.0k4](/packages/altis-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
