PHPackages                             ac/web-services-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. ac/web-services-bundle

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

ac/web-services-bundle
======================

Provides tools for developing RESTful APIs.

0.4.5(10y ago)01.1k2[6 issues](https://github.com/AmericanCouncils/WebServicesBundle/issues)MITPHPPHP &gt;=5.4.0

Since Jun 28Pushed 9y ago5 watchersCompare

[ Source](https://github.com/AmericanCouncils/WebServicesBundle)[ Packagist](https://packagist.org/packages/ac/web-services-bundle)[ RSS](/packages/ac-web-services-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (28)Used By (0)

ACWebServicesBundle
===================

[](#acwebservicesbundle)

[![Build Status](https://camo.githubusercontent.com/defd0517266b4c18dc7d2eaa8e19a0fa1b3434a08a84718442cf2a71588bbcfa/68747470733a2f2f7472617669732d63692e6f72672f416d65726963616e436f756e63696c732f576562536572766963657342756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/AmericanCouncils/WebServicesBundle)

This bundle provides generic api workflow tools for developing RESTful apis.

*NIH:* A lot of the functionality in this bundle already exists in [FOSRestBundle](https://github.com/FriendsOfSymfony/FOSRestBundle), use that if you want safety. This is periodically under heavy development.

Features
--------

[](#features)

- Request lifecycle events dispatched for registered *API events*
- Object de-serializer that leverages JMS Metadata to serialize incoming data into already existing objects
- Optionally include response data as part of the outgoing response
- By default handles xml, json, jsonp and yml responses
- Easily convert validation errors to useful API responses
- Easil serialize incoming data into existing objects

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

[](#installation)

1. require `"ac/web-services-bundle": "~0.2.0"` in your `composer.json`
2. update it w/ composer: `composer update ac/web-services-bundle`
3. enable in your `AppKernel.php`:

    ```
    use AC\WebServicesBundle\ACWebServicesBundle;

    //...

    public function getBundles()
    {
        //...
        $bundles = array(
            //...
            new ACWebServicesBundle()
            //...
        );
        //....
    }
    ```
4. Configure the bundle in your `app/config/config.yml`:

    This is an example configuration block. All sections are optional and explained in more detail in subsequent sections.

    ```
    ac_web_services:
        serializer:
            allow_deserialize_into_target: true
        response_format_headers:
            yml:
                'Content-Type': 'text/x-yaml; charset=UTF-8'
            csv:
                'Content-Type': 'text/csv; charset=UTF-8'
        paths:
            '{^/api/override}':
                include_exception_data: false
                include_response_data: false
                allow_code_suppression: false
                allow_jsonp: false
                default_response_format: json
            '{^/api/}':
                include_exception_data: true
                include_response_data: true
                allow_code_suppression: true
                allow_jsonp: true
                default_response_format: json
                http_exception_map:
                    'AC\WebServicesBundle\Tests\Fixtures\FixtureBundle\BundleException': { code: 403, message: 'Custom error message' }
                additional_headers:
                    'x-custom-acwebservices': 'foo-bar-baz'
    ```

API Paths Configuration
-----------------------

[](#api-paths-configuration)

Generally speaking, you configure some general behavior for your API by setting values that apply to certain routes. When a request matches a configured path, an event subscriber is registered with the relevant configuration. This subscriber fires extra api events, similar to the kernel events. From your controllers you can return raw data structures, which may include objects configured for serialization via the `JMSSerializerBundle`. Information returned from a controller will automatically be serialized into the requested data transfer format by the `serializer` service.

For example:

1. Request to `http://example.com/api/foo?_format=json`
2. Routed to controller `MyBundle\Controller\FooController::someAction`
3. Which looks like this:

    ```
