PHPackages                             netmex/response - 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. netmex/response

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

netmex/response
===============

v1.0.0(1y ago)015MITPHP

Since May 13Pushed 1y agoCompare

[ Source](https://github.com/netmexmedia/Response)[ Packagist](https://packagist.org/packages/netmex/response)[ RSS](/packages/netmex-response/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Netmex Response Bundle
======================

[](#netmex-response-bundle)

This Symfony bundle allows you to handle API responses using custom response classes. It provides a `ResponseInterface` to standardize how your application manages its responses, making it easy to handle and customize API output and error handling.

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

[](#installation)

`composer require netmex/response`

Usage
-----

[](#usage)

Implement the `Netmex\Response\ResponseInterface` in your custom response class.

When you implement the ResponseInterface, you need to define the two methods toResponse and onError.

`toResponse(Request $request): Response`This method is responsible for converting your data into a valid Symfony `Response` object (e.g., `JsonResponse` or any other type based on your needs). It is used for handling successful API responses.

`onError(HttpException $error): Response`This method is called when an error occurs (for example, when an exception is thrown). It allows you to handle error responses and return custom error messages or formats.

##### Example Response Class

[](#example-response-class)

```
