PSX is a framework written in PHP which helps
to build clean and documented REST APIs.

PSX provides tools to handle common API tasks like data serialization, validation, documentation, API versioning and testing. So you can concentrate on building the actual business logic of your API. Some reasons you might want to use PSX:

  • Automatic documentation generation
  • Generate controller and model classes from a schema API specification
  • Work with POPOs for incoming and outgoing data
  • Automatic generation of schema specifications (RAML, OAI)
  • Validate incoming data based on JsonSchema
  • Based on multiple independent components
class Controller extends SchemaApiAbstract
{
    /**
     * @Inject
     */
    protected $repository;

    /**
     * @QueryParam(name="startIndex", type="integer")
     * @Outgoing(code=200, schema="Acme\Model\Collection")
     */
    protected function doGet()
    {
        $startIndex = $this->queryParameters->getProperty('startIndex') ?: 0;
        
        return $this->repository->fetchAll($startIndex);
    }

    /**
     * @Incoming(schema="Acme\Model\News")
     * @Outgoing(code=201, schema="Acme\Model\Message")
     */
    protected function doPost($news)
    {
        $this->repository->insert('acme_news', [
            'title'      => $news->getTitle(),
            'content'    => $news->getContent(),
            'createDate' => new \DateTime(),
        ]);

        return new Message(true, 'Create successful');
    }
}
class News
{
    /**
     * @Type("string")
     * @MinLength(3)
     * @MaxLength(64)
     */
    protected $title;

    /**
     * @Type("string")
     * @MaxLength(255)
     */
    protected $content;

    /**
     * @Type("datetime")
     */
    protected $createDate;

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function getContent()
    {
        return $this->content;
    }

    public function setContent($content)
    {
        $this->content = $content;
    }

    public function getCreateDate()
    {
        return $this->createDate;
    }

    public function setCreateDate(\DateTime $createDate)
    {
        $this->createDate = $createDate;
    }
}
class Collection
{
    /**
     * @Type("integer")
     */
    protected $totalResults;

    /**
     * @Type("array<Acme\Model\News>")
     */
    protected $entry;

    public function getTotalResults()
    {
        return $this->totalResults;
    }

    public function setTotalResults($totalResults)
    {
        $this->totalResults = $totalResults;
    }

    public function getEntry()
    {
        return $this->entry;
    }

    public function setEntry(array $entry)
    {
        $this->entry = $entry;
    }
}

This was only a short introduction to give you an insight how a PSX application works. If you are excited about the possibilities as we are you can read the about page for more informations or checkout the offical documentation.