PHPackages                             phidias/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. [API Development](/categories/api)
4. /
5. phidias/api

ActiveLibrary[API Development](/categories/api)

phidias/api
===========

Phidias API Server

01712PHP

Since Jun 26Pushed 1y ago3 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (2)

Phidias API
===========

[](#phidias-api)

##### Available via composer

[](#available-via-composer)

`composer require phidias/api`

#### Overview

[](#overview)

##### Declare resources with a simple syntax

[](#declare-resources-with-a-simple-syntax)

```
use Phidias\Api\Server;

Server::resource("/")
    ->on("get", function() {
        return "hello world";
    });

Server::run();

```

##### Keep your application logic separate

[](#keep-your-application-logic-separate)

```
class Book
{
    public $title;
    public $review;

    public function __construct()
    {
        $rand = rand(1, 10);

        $this->title  = "$rand things I hate about you";
        $this->review = "I just wasted $rand hours";
    }
}

class BookManager
{
    public function getBookList()
    {
        // ... do your voodoo
        $books = [new Book, new Book, new Book];

        return $books;
    }
}

Server::resource("/books")
    ->on("get", "BookManager->getBookList()");

Server::run();

```

##### Route URL Attributes

[](#route-url-attributes)

```
Server::resource("/books/{bookId}")
    ->on("get", "BookManager->getBook({bookId})");

```

##### Handle multiple response formats

[](#handle-multiple-response-formats)

```
Server::resource("/books/{bookId}")
    ->on("get", Server::action()
        ->controller("BookManager->getBook({bookId})")

        ->render("text/html",       "BookManager->toHtml({output})")
        ->render("application/xml", "BookManager->toXml({output})")
    );

```

##### An example showcasing most features

[](#an-example-showcasing-most-features)

```
