{"id":15045120,"url":"https://github.com/joubertredrat/apihelperbundle","last_synced_at":"2025-10-25T00:31:40.513Z","repository":{"id":62534291,"uuid":"274555520","full_name":"joubertredrat/ApiHelperBundle","owner":"joubertredrat","description":"This bundle provides easy way to work with API urls into your Symfony application","archived":false,"fork":false,"pushed_at":"2020-07-08T17:18:27.000Z","size":56,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-31T04:32:06.826Z","etag":null,"topics":["api-json","api-rest","json-api","php","symfony","symfony-bundle","symfony4","symfony5"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/redrat/api-helper-bundle","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joubertredrat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-24T02:26:20.000Z","updated_at":"2020-09-29T17:55:01.000Z","dependencies_parsed_at":"2022-11-02T15:00:32.321Z","dependency_job_id":null,"html_url":"https://github.com/joubertredrat/ApiHelperBundle","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joubertredrat%2FApiHelperBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joubertredrat%2FApiHelperBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joubertredrat%2FApiHelperBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joubertredrat%2FApiHelperBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joubertredrat","download_url":"https://codeload.github.com/joubertredrat/ApiHelperBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238053514,"owners_count":19408699,"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":["api-json","api-rest","json-api","php","symfony","symfony-bundle","symfony4","symfony5"],"created_at":"2024-09-24T20:51:28.836Z","updated_at":"2025-10-25T00:31:40.201Z","avatar_url":"https://github.com/joubertredrat.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Api Helper Bundle\n\n[![Build Status](https://travis-ci.org/joubertredrat/ApiHelperBundle.svg?branch=master)](https://travis-ci.org/joubertredrat/ApiHelperBundle)\n[![Maintainability](https://api.codeclimate.com/v1/badges/b45a7ebaf29e793ea918/maintainability)](https://codeclimate.com/github/joubertredrat/ApiHelperBundle/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/b45a7ebaf29e793ea918/test_coverage)](https://codeclimate.com/github/joubertredrat/ApiHelperBundle/test_coverage)\n[![Latest Stable Version](https://poser.pugx.org/redrat/api-helper-bundle/v)](https://packagist.org/packages/redrat/api-helper-bundle)\n[![Total Downloads](https://poser.pugx.org/redrat/api-helper-bundle/downloads)](https://packagist.org/packages/redrat/api-helper-bundle/stats)\n[![License](https://poser.pugx.org/redrat/api-helper-bundle/license)](https://packagist.org/packages/redrat/api-helper-bundle)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjoubertredrat%2FApiHelperBundle.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjoubertredrat%2FApiHelperBundle?ref=badge_shield)\n\n\nThis Symfony bundle provides configuration to validate and convert data for API routes.\n\n#### First question, why?\n\nBecause I needed a bundle with configurable url prefix to use as API routes. For default in Symfony, only requests with content type `multipart/form-data` and `application/x-www-form-urlencoded` will have Request class with parameters data easily accessible by `get()` method, as example below.\n\n```php\nclass MyController\n{\n    public function handleForm(Request $request): Response\n    {\n        $myName = $request-\u003eget('myName'); // return Joubert RedRat\n    }\n\n    public function handleApi(Request $request): Response\n    {\n        $myName = $request-\u003eget('myName'); // return null\n    }\n}\n```\n\nWith this bundle will be possible to configure which routes will work as API routes and any request with content type `application/json` will have Request class with parameters data easily accessible too.\n\n#### Okay, how to install then?\n\nEasy my friend, install with the composer.\n\n```bash\ncomposer require redrat/api-helper-bundle\n```\n\n#### Configure the bundle (if necessary)\n\nIf your composer don't like Symfony recipes contrib, don't worry, you can configure too.\n\n* Open `config/bundles.php` and add the bundle like below.\n\n```php\nreturn [\n    Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle::class =\u003e ['all' =\u003e true],\n    RedRat\\ApiHelperBundle\\ApiHelperBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n* Create `config/packages/redrat_api_helper.yaml` and set initial config like below.\n\n```yaml\nredrat_api_helper:\n    paths:\n```\n\n#### How to bundle works?\n\nThis bundle works with a configuration defined in `config/packages/redrat_api_helper.yaml`. Into this file you will config which url path prefix will work as API url, like example below:\n\n```yaml\nredrat_api_helper:\n    paths:\n        my_amazing_api_v1:\n            url_path_prefix: /api/v1\n        other_api_v3:\n            url_path_prefix: /api/v3\n        old_not_cute_api:\n            url_path_prefix: /legacy/api\n```\n\nYou can configure one or more url path prefixes as you need.\n\nAfter this, all url path that matches with a configuration will be acted by the bundle and will be validated and data putted into request class.\n\nLook that only routes that matches will be acted by the bundle, like example below using configuration above.\n\n```\nGET /api/v1/accounts/users =\u003e matches\nPOST /api/login =\u003e doesn't matches\nDELETE /api/v2/emails =\u003e doesn't matches\nPUT /api/v1/accounts/users/46 =\u003e matches\nPATCH /api/v1/accounts/users =\u003e matches\nGET /about-us =\u003e doesn't matches\nGET /legacy/api/v1/cities =\u003e matches\n```\n\n### Validations\n\nThis bundle performs 2 validations in a route matched with configuration.\n\n##### Content-type\n\nRoute matched should have `application/json` as Content-Type with methods `POST`, `PUT` and `PATCH`.\nIf not pass by this validation, bundle will return error below.\nMethods `GET` and `DELETE` normally don't contain body data, then these methods isn't validated.\n\n```\n\u003c HTTP/2 400\n\n{\n  \"error\": \"Invalid Content-Type, expected application\\/json, got application\\/x-www-form-urlencoded\"\n}\n```\n##### Valid json data\n\nRoute matched should have valid [RFC7159](http://www.faqs.org/rfcs/rfc7159.html) json data in body.\nIf not pass by this validation, bundle will return error below.\n\n```\n\u003c HTTP/2 400\n\n{\n  \"error\": \"Invalid json body data\"\n}\n```\n\n### Author\n\n[Me](https://github.com/joubertredrat) and the [contributors](https://github.com/joubertredrat/ApiHelperBundle/graphs/contributors).\n\n### License\n\nThe cute and amazing [MIT](https://github.com/joubertredrat/ApiHelperBundle/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoubertredrat%2Fapihelperbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoubertredrat%2Fapihelperbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoubertredrat%2Fapihelperbundle/lists"}