PHPackages                             helmich/flow-resttools - 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. helmich/flow-resttools

AbandonedArchivedTypo3-flow-package[API Development](/categories/api)

helmich/flow-resttools
======================

Utility package for creating RESTful webservices with TYPO3 Flow

58821PHP

Since Jan 18Pushed 10y ago5 watchersCompare

[ Source](https://github.com/martin-helmich/flow-resttools)[ Packagist](https://packagist.org/packages/helmich/flow-resttools)[ RSS](/packages/helmich-flow-resttools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (1)

Toolkit for developing RESTful webservices with TYPO3 Flow
==========================================================

[](#toolkit-for-developing-restful-webservices-with-typo3-flow)

Author
------

[](#author)

Martin Helmich

Synopsis
--------

[](#synopsis)

This package contains a set of helper classes for implementing RESTful webservices with TYPO3 Flow.

It specifically handles the following concerns:

- Controller configuration
- Serializing domain objects
- Request body handling
- Exception handling

Controller configuration
------------------------

[](#controller-configuration)

This package offers a [RestController](Classes/Helmich/RestTools/Mvc/Controller/RestController.php)that you may use when implementing controllers. Please note that this class **does not** extend Flow's own `RestController` class.

The `RestController` class contains a default view configuration that enables the controller to support JSON, YAML, XML and MSGPACK representations (currently, output only. Input is still handled by Flow's default MediaConverter, which supports only JSON and XML). Stay tuned for more.

Serializing domain objects
--------------------------

[](#serializing-domain-objects)

This package contains an API for converting domain objects into representations. Unlike TYPO3 Flow's `JsonView`, which relies on automatically building the representation based on values returned by an object's getter method, this package requires explicit normalizer classes to be supplied for each domain model. I prefer this design because it offers more control on how object representations are generated.

In general, object serialization is performed in two steps:

- *Normalization*: Convert domain objects into a plain PHP array. This step is domain-specific. This means that you have to specify a *Normalizer* class for each domain object you want to present. These classes have to implement the `NormalizerInterface` (see [source](Classes/Helmich/RestTools/Rest/Normalizer/NormalizerInterface)) and return a scalar PHP type -- usually a (nested) array.
- *Serialization*: Converts scalar PHP types generated by the normalization step into a string represantation. This step is *not* domain-specific. Currently, there are normalizers for JSON, YAML and [MessagePack](http://msgpack.org).

Request body handling
---------------------

[](#request-body-handling)

### Motivation

[](#motivation)

One thing that's bugged me most about Flow is it's limited handling of request bodies. Deserializing JSON bodies works only when you wrap your resources in an envelope object that Flow can then map to the request arguments.

For instance, consider the following controller action:

```
public function testAction(Product $product) {
  // ...
}
```

To successfully map the `$product` argument, your JSON request body would also need a `"product"` property:

```
{
  "product": {
    # ...
  }
}
```

### Solution

[](#solution)

You can use the annotation `Rest\BodyParam` to denote a controller action argument that should be populated from the request body:

```
