PHPackages                             wizards/rest-api - 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. wizards/rest-api

ActiveLibrary

wizards/rest-api
================

A set of services to help you create beautiful REST APIs

0.9.0(5y ago)37.6k3[1 issues](https://github.com/wizardstechnologies/php-rest-api/issues)MITPHPPHP &gt;=7.3CI failing

Since Aug 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wizardstechnologies/php-rest-api)[ Packagist](https://packagist.org/packages/wizards/rest-api)[ RSS](/packages/wizards-rest-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (31)Used By (0)

Wizards Technologies' PHP REST API Library
==========================================

[](#wizards-technologies-php-rest-api-library)

A framework agnostic PHP library based on [fractal](https://fractal.thephpleague.com/) to help you craft beautiful REST APIs.

[![Build Status](https://camo.githubusercontent.com/7a1a60c22dd2587aa8e0355c2f0d4aab822c915aafe4a6062ba8a5c73f12229c/68747470733a2f2f7472617669732d63692e6f72672f77697a61726473746563686e6f6c6f676965732f7068702d726573742d6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/wizardstechnologies/php-rest-api)

Goals
-----

[](#goals)

The main goal is to provide an easy to use and powerful REST API library that seamlessly integrates with modern frameworks.

The paradigm reads as follow:

- A method will ask for a given resource (usually a controller), sending over an [http request](https://www.php-fig.org/psr/psr-7/) that we *Parse* to find standardized parameters. A resource is a data object, that you can fetch from a data store - as a collection or as an entry. Thoses resources can have relationships, can be filtered, can be modified, ....
- The library will fetch the resource(s) according to the given *Object Manager* (something like an orm, odm) and request
- It then transforms the data into standardized resource(s) given the provided *Object Reader* (there are many ways to configure resources, such as doctrine annotations, configuration files, ...)
- It sends the found resources to fractal with the appropriate *Transformer* for serialization on the given output format.

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

[](#installation)

```
composer require wizards/rest-api

```

Usage
-----

[](#usage)

The library's conventions are based on the [jsonapi ones](http://jsonapi.org/format/).

### Query Paramters

[](#query-paramters)

The *RestQueryParser* will expect those query parameters:

- **Collection**

    - `sort`
        - `name` to sort by ascending name
        - `-name` to sort by descending name
        - Example: `?sort=-date`
    - `filter` to filter resources by values.
        - multiple values for filters should be provided coma-separated.
        - Example: `?filter[name]=dupont,dupond&filter[surname]=thomas`
    - `filteroperator`
        - to change the default filter opetator from `=` to something else.
        - available operators: ``, `=`, `!=`, `in`.
        - Example: `?filter[age]=18&filteroperator[age]=>=`
    - `include` to include relationships data.
        - Example: `/books?include=author,editor`
    - `limit`: how many results you want to see by page.
    - `page`: the page number. Starts at 1.
- **Single resource**

    - `include` to include relationships data. Example: `/books/1?include=author,editor`

Examples
--------

[](#examples)

### Plain ol' PHP

[](#plain-ol-php)

```
