{"id":18668136,"url":"https://github.com/eonx-com/apiformats","last_synced_at":"2026-01-11T06:52:07.710Z","repository":{"id":52414720,"uuid":"127830174","full_name":"eonx-com/apiformats","owner":"eonx-com","description":"Package to handle multiple formats in API","archived":false,"fork":false,"pushed_at":"2021-04-29T21:04:20.000Z","size":320,"stargazers_count":3,"open_issues_count":7,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T17:28:48.375Z","etag":null,"topics":["library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eonx-com.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-03T00:53:43.000Z","updated_at":"2022-09-08T23:23:37.000Z","dependencies_parsed_at":"2022-09-03T22:11:13.030Z","dependency_job_id":null,"html_url":"https://github.com/eonx-com/apiformats","commit_stats":null,"previous_names":["loyaltycorp/apiformats"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fapiformats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fapiformats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fapiformats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eonx-com%2Fapiformats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eonx-com","download_url":"https://codeload.github.com/eonx-com/apiformats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248498436,"owners_count":21114124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library"],"created_at":"2024-11-07T08:41:31.636Z","updated_at":"2026-01-11T06:52:07.704Z","avatar_url":"https://github.com/eonx-com.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Formats\n\n## Installation\nUse [Composer](https://getcomposer.org/) to install the package in your project:\n\n```\ncomposer require eoneopay/apiformats\n```\n\n## Formats\nBy default the package handle **JSON** (application/json) and **XML** (application/xml, text/xml) formats.\nIf you want to handle different formats or want to implement your own **JSON**/**XML** encoding logic, the only thing\nyou need to do is creating your encoder implementing `\\EoneoPay\\ApiFormats\\Interfaces\\RequestEncoderInterface` and\ntell the package to use it, with which Mime types as explained in the [Configuration](#configuration) section.\n\n## Integration\n#### Laravel\nTo integrate the package into your [Laravel](https://laravel.com) or [Lumen](https://lumen.laravel.com)\nyou need to register the following service provider and middleware:\n\n- **ServiceProvider:** `\\EoneoPay\\ApiFormats\\Bridge\\Laravel\\Providers\\ApiFormatsServiceProvider`\n- **Middleware:** `\\EoneoPay\\ApiFormats\\Bridge\\Laravel\\Middlewares\\ApiFormatsMiddleware`\n\nThat's it! Your application is now able to easily receive requests and generate responses in several formats.\n\n###### Formatted Api Response\nIf you want to customise the generated response as its status code or headers without handling\nbody encoding yourself, the package provides the `\\EoneoPay\\ApiFormats\\Bridge\\Laravel\\Responses\\FormattedApiResponse`\nobject you can return from your controllers/middlewares. The `FormattedApiResponse` accept three parameters through its\nconstructor as following:\n\n- **$content (mixed):** array or object able to be cast as an array\n- **$statusCode (int):** status code of response, default as 200\n- **$headers (array):** headers of response, default as empty array\n\n## Configuration\nThe philosophy of the package is to map encoders to a list of MIME types that they can handle through an array \nas following:\n\n```php\n$formats = [\n    \u003cRequestEncoderInterface\u003e =\u003e [\u003cmime_type\u003e, \u003cmime_type\u003e, ...]\n];\n```\n\nEach MIME type can be the exact name as `application/json` or a [Regex](http://php.net/manual/en/reference.pcre.pattern.syntax.php)\nused to match multiple MIME types as `application/vnd.eoneopay.v[0-9]+\\+json`.\n\n#### Laravel\nTo configure supported formats in your application, create a `api-formats.php` config file with a `formats`\narray using the encoders class as key and array of associated Mime types as value:\n\n```php\n// config/api-formats.php\n\nreturn [\n    'formats' =\u003e [\n        JsonRequestEncoder::class =\u003e ['application/json'],\n        XmlRequestEncoder::class =\u003e ['(application|text)/xml'],\n        YourCustomerEncoder::class =\u003e ['you-custom-mime-type']\n    ]\n]; \n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonx-com%2Fapiformats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feonx-com%2Fapiformats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feonx-com%2Fapiformats/lists"}