Download the PHP package arturdoruch/simple-rest-bundle without Composer
On this page you can find all versions of the php package arturdoruch/simple-rest-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arturdoruch/simple-rest-bundle
More information about arturdoruch/simple-rest-bundle
Files in arturdoruch/simple-rest-bundle
Package simple-rest-bundle
Short Description Collection of useful functions for build RESTful API
License MIT
Informations about the package simple-rest-bundle
SimpleRestBundle
Symfony bundle with collection of useful functions for build RESTful API.
Installation
Register bundle in Kernel
class of your application.
In Symfony 3
In Symfony >= 4
Suggestions
- For serializing and normalizing HTTP response data install the
jms/serializer-bundle
package. - For translating API error messages install the
symfony/translation
package.
Configuration
Bundle configuration. Available options:
Usage
Controller
In your controller import the ArturDoruch\SimpleRestBundle\RestTrait
trait
to have access to common REST functions.
Examples of handling API requests.
Request error events
The event names are defined in ArturDoruch\SimpleRestBundle\Http\RequestErrorEvents
class.
Available events:
-
Name
artur_doruch_simple_rest.request_error.pre_create_response
Class constantRequestErrorEvents::PRE_CREATE_RESPONSE
Event class passed to the listener methodArturDoruch\SimpleRestBundle\Event\RequestErrorEvent
The event is dispatched before creating the HTTP response, while API endpoint has been requested and an exception occurred. Allows to modify an exception.
-
Name
artur_doruch_simple_rest.request_error.post_create_response
Class constantRequestErrorEvents::POST_CREATE_RESPONSE
Event class passed to the listener methodArturDoruch\SimpleRestBundle\Event\RequestErrorEvent
The event is dispatched after creating the HTTP response, while API endpoint has been requested and an exception occurred. Provides access to the HTTP response.
Register event listener
Example:
See the Symfony Events and Event Listeners documentation for details.
Endpoint response
To create endpoint response use the ArturDoruch\SimpleRestBundle\RestTrait::createResponse()
method.
By default, the response has the Content-Type: application/json
header set.
Endpoint request error
The response body for an endpoint request error contains:
- Content type:
application/json
- Content body parameters:
status
(string) HTTP status code.type
(string) Type of the error.message
(string) Error message.details
(array) Error details.
All versions of simple-rest-bundle with dependencies
symfony/config Version ^3.0|^4.0|^5.0
symfony/dependency-injection Version ^3.0|^4.0|^5.0
symfony/event-dispatcher Version ^3.0|^4.0|^5.0
symfony/form Version ^3.0|^4.0|^5.0
symfony/http-foundation Version ^3.0|^4.0|^5.0
symfony/http-kernel Version ^3.0|^4.0|^5.0