PHPackages                             linkorb/primate - 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. linkorb/primate

ActiveLibrary[API Development](/categories/api)

linkorb/primate
===============

Primate: Restful API Library

059PHPCI failing

Since Apr 30Pushed 10y ago3 watchersCompare

[ Source](https://github.com/linkorb/primate)[ Packagist](https://packagist.org/packages/linkorb/primate)[ RSS](/packages/linkorb-primate/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Primate: The API ToolKit
========================

[](#primate-the-api-toolkit)

[![](https://camo.githubusercontent.com/b67aa6bb55c4b0a1497bf099273c5f97ec0ada1c3f78a73bbd8c9425422f6e6b/687474703a2f2f7777772e6561727468746f7563686e6577732e636f6d2f6d656469612f3338353833362f73637265656e2d73686f742d323031342d30382d32312d61742d3130313234342d616d2d363430783833345f47616c6c6572794c617267652e706e67)](https://camo.githubusercontent.com/b67aa6bb55c4b0a1497bf099273c5f97ec0ada1c3f78a73bbd8c9425422f6e6b/687474703a2f2f7777772e6561727468746f7563686e6577732e636f6d2f6d656469612f3338353833362f73637265656e2d73686f742d323031342d30382d32312d61742d3130313234342d616d2d363430783833345f47616c6c6572794c617267652e706e67)

Primate is a library that helps creating beautiful REST APIs.

It is heavily inspired by [Stormpath's "The Fundamentals of REST API Design"](https://stormpath.com/blog/fundamentals-rest-api-design/)

Using Primate
-------------

[](#using-primate)

First you'll need to instantiate Primate, before your app can serve requests:

```
use Primate\Primate;

$primate = new Primate();
$primate->setBaseUrl('http://primate.example.com/api/v1');
$primate->setProperty('tenant', 'joe');
$primate->setProperty('x', 'y');
```

You'll notice that the BaseUrl of your API is set on the Primate instance, in order to output correct urls.

Additionally, we're registering some arbitrary properties to define the context of the requests. You can use these properties later in order to fetch resources.

Resources and Collections
-------------------------

[](#resources-and-collections)

In Primate APIs, a client can work with Resources and Collections.

- A **Resource** is simply an "object" in your application. For example, a User, a Product, etc.
- A **Collection** is simply an array of **Resources**.

Types
-----

[](#types)

Each **Resource** is of a specified **Type**.

In Primate, you'll need to register one or more Types before you can use them. For example:

```
$repo = new MyContactRepository();
$type = new Type('contacts', $repo);
$primate->registerType($type);
```

Each Type has a name and a repository. The Repository can be any class that's implementing the `Primate\RepositoryInterface`.

It's recommended to take your existing application repositories, and make them implement this interface.

For example:

```
