PHPackages                             paysera/lib-api-bundle - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. paysera/lib-api-bundle

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

paysera/lib-api-bundle
======================

Symfony bundle that allows easy configuration for your REST endpoints.

1.8.1(1y ago)713.8k9[1 issues](https://github.com/paysera/lib-api-bundle/issues)1MITPHPPHP ^7.1 || ^8.0CI passing

Since Dec 1Pushed 1y ago4 watchersCompare

[ Source](https://github.com/paysera/lib-api-bundle)[ Packagist](https://packagist.org/packages/paysera/lib-api-bundle)[ RSS](/packages/paysera-lib-api-bundle/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)Dependencies (16)Versions (17)Used By (1)

PayseraApiBundle
================

[](#payseraapibundle)

[![Build Status](https://github.com/paysera/lib-api-bundle/workflows/CI/badge.svg)](https://github.com/paysera/lib-api-bundle/actions)[![Latest Stable Version](https://camo.githubusercontent.com/bb335b95b547be3fdaf0ee06614c0d7d0decf3b5e6473b5b98c6e63dbf8be7a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706179736572612f6c69622d6170692d62756e646c652e737667)](https://packagist.org/packages/paysera/lib-api-bundle)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Coverage Status](https://camo.githubusercontent.com/e0725d2bd63e006e26c6f3ccaf86a0686a99b371f3bad2fe0e44b230c52d6739/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f706179736572612f6c69622d6170692d62756e646c652e737667)](https://scrutinizer-ci.com/g/paysera/lib-api-bundle/code-structure)[![Quality Score](https://camo.githubusercontent.com/b308c9135ed4076e80711589b40597bdb9b2ae158b252c960e08cc9a3f5bfc7d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f706179736572612f6c69622d6170692d62756e646c652e737667)](https://scrutinizer-ci.com/g/paysera/lib-api-bundle)[![Total Downloads](https://camo.githubusercontent.com/3792e2244f887cd18d40f733c87f8d8bacfc176174673a32375a5270fc71b7e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706179736572612f6c69622d6170692d62756e646c652e737667)](https://packagist.org/packages/paysera/lib-api-bundle)

Symfony bundle that allows easy configuration for your REST endpoints.

Why?
----

[](#why)

If you write quite many REST endpoints, some of the code or the structure itself gets repeated. If you want to add some functionality to all your endpoints, this could also get troublesome if you just wrote some custom code for each of them.

### Difference from API Platform

[](#difference-from-api-platform)

API Platform gives lots of API specification options, documentation generation and such. This is available as it knows all the relations and fields in your objects. But for that, you need to configure the objects for all these features, including serialization options.

This approach is perfect for small applications but can be a pain on larger ones or the ones that need long term support and tend to change time to time.

When some custom functionality is needed, it's really easier to just implement it in code than to correctly configure it (if such configuration is even available).

This bundle gives a bit more control:

- each route is defined explicitly and has controller action that's executed. This allows to track the execution better and use any custom programming code when needed;
- for serialization/normalization code is used, not configuration. This makes it also more explicit and configurable. Tightly coupling REST interface with business model does not seem as a good idea for us.

It's a bit more boilerplate, but easily customisable when needed.

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

[](#installation)

```
composer require paysera/lib-api-bundle
```

If you're not using symfony flex, add the following bundles to your kernel:

```
new PayseraNormalizationBundle(),
new PayseraApiBundle(),

```

Configuration
-------------

[](#configuration)

```
paysera_api:
    locales: ['en', 'lt', 'lv']        # Optional list of accepted locales
    validation:
        property_path_converter: your_service_id    # Optional service ID to use for property path converter
    path_attribute_resolvers:          # Registered path attribute resolvers. See below for more information
        App\Entity\PersistedEntity:
            field: identifierField
    pagination:
        total_count_strategy: optional # If should we provide or allow total count of resources (by default)
        maximum_offset: 1000           # If we should limit offset passed to pager for performance reasons
        maximum_limit: 1000            # Maximum limit for one page of results
        default_limit: 100             # Default limit for one page of results
```

Usage
-----

[](#usage)

### Creating resource

[](#creating-resource)

To normalize and denormalize data from requests and to responses, [PayseraNormalizationBundle](https://github.com/paysera/lib-normalization-bundle) is used. It works by writing a class for each of your resource. This makes it explicit and allows easy customization for mapping to/from your domain models (they usually are Doctrine entities).

Normalizer example:

```
