Skip to content

Commit 159acb3

Browse files
committed
📖 Improve README
1 parent f9ca946 commit 159acb3

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

README.md

+52-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,56 @@
11
# Symfony JSON rest API [![Build Status](https://travis-ci.org/rezzza/symfony-json-rest-api.svg?branch=master)](https://travis-ci.org/rezzza/symfony-json-rest-api)
22

3-
Symfony stuff to help building a json rest api
3+
Symfony stuff to help building a JSON REST api :
4+
- Support JSON payload
5+
- Support LINK headers
6+
- Handle exception as JSON response
7+
- Possibility to validate json payload through json schema
8+
- Possibility to map custom exception to http code
49

5-
We will find :
6-
* [JsonBodyListener](JsonBodyListener.php) to convert raw JSON from body of your requets into request attributes
7-
* [LinkRequestListener](LinkRequestListener.php) to validate and transform link header into request attributes
8-
* [JsonExceptionHandler](JsonExceptionHandler.php) to transform exception into JsonResponse
10+
Here is a simple setup to start :
11+
```xml
12+
<?xml version="1.0" ?>
913

10-
See usage into our [symfony-micro-edition](https://github.com/rezzza/symfony-micro-edition/blob/master/app/services/ui.xml)
14+
<container xmlns="http://symfony.com/schema/dic/services"
15+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
17+
18+
<services>
19+
<service id="json_body_listener.ui" class="Rezzza\SymfonyRestApiJson\JsonBodyListener">
20+
<argument type="service">
21+
<service class="Rezzza\SymfonyRestApiJson\PayloadValidator">
22+
<argument type="service">
23+
<service class="Rezzza\SymfonyRestApiJson\JsonSchemaTools" />
24+
</argument>
25+
</service>
26+
</argument>
27+
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="24" />
28+
</service>
29+
30+
<service id="link_request_listener.ui" class="Rezzza\SymfonyRestApiJson\LinkRequestListener">
31+
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="10" />
32+
</service>
33+
34+
<service id="json_exception_handler.ui" class="Rezzza\SymfonyRestApiJson\JsonExceptionHandler">
35+
<argument type="service">
36+
<service class="Rezzza\SymfonyRestApiJson\ExceptionHttpCodeMap">
37+
<argument>%exception_http_code_map%</argument>
38+
</service>
39+
</argument>
40+
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="32" />
41+
</service>
42+
43+
<service id="json_exception_controller.ui" class="Rezzza\SymfonyRestApiJson\JsonExceptionController">
44+
<argument>%kernel.debug%</argument>
45+
<argument>%show_exception_token%</argument>
46+
</service>
47+
48+
<service id="ui.event_listener.exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
49+
<tag name="kernel.event_subscriber" />
50+
<tag name="monolog.logger" channel="request" />
51+
<argument>json_exception_controller.ui:showException</argument>
52+
<argument type="service" id="logger" on-invalid="null" />
53+
</service>
54+
</services>
55+
</container>
56+
```

0 commit comments

Comments
 (0)