{"id":14983865,"url":"https://github.com/pew-pew-team/http-factory","last_synced_at":"2025-04-10T19:41:36.159Z","repository":{"id":228184370,"uuid":"773349419","full_name":"pew-pew-team/http-factory","owner":"pew-pew-team","description":"Factory for request decoding and response encoding","archived":false,"fork":false,"pushed_at":"2024-03-17T13:05:58.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T16:43:55.877Z","etag":null,"topics":["accept","bundle","content-type","decoder","encoder","factory","http","request","response","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","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/pew-pew-team.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-17T12:34:50.000Z","updated_at":"2024-03-18T14:26:09.000Z","dependencies_parsed_at":"2024-03-17T14:04:03.545Z","dependency_job_id":"5cf7b980-020d-4901-89c8-29ba69b11439","html_url":"https://github.com/pew-pew-team/http-factory","commit_stats":null,"previous_names":["pew-pew-team/http-factory"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pew-pew-team%2Fhttp-factory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pew-pew-team%2Fhttp-factory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pew-pew-team%2Fhttp-factory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pew-pew-team%2Fhttp-factory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pew-pew-team","download_url":"https://codeload.github.com/pew-pew-team/http-factory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281415,"owners_count":21077423,"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":["accept","bundle","content-type","decoder","encoder","factory","http","request","response","symfony","symfony-bundle"],"created_at":"2024-09-24T14:08:05.585Z","updated_at":"2025-04-10T19:41:36.119Z","avatar_url":"https://github.com/pew-pew-team.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/pew-pew-team\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/pew-pew-team/.github/master/assets/logo.svg\" width=\"128\" height=\"128\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/pew-pew/http-factory\"\u003e\u003cimg src=\"https://poser.pugx.org/pew-pew/http-factory/require/php?style=for-the-badge\" alt=\"PHP 8.3+\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/pew-pew/http-factory\"\u003e\u003cimg src=\"https://poser.pugx.org/pew-pew/http-factory/version?style=for-the-badge\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/pew-pew/http-factory\"\u003e\u003cimg src=\"https://poser.pugx.org/pew-pew/http-factory/v/unstable?style=for-the-badge\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/pew-pew-team/http-factory/blob/master/LICENSE\"\u003e\u003cimg src=\"https://poser.pugx.org/pew-pew/http-factory/license?style=for-the-badge\" alt=\"License MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/pew-pew-team/http-factory/actions\"\u003e\u003cimg src=\"https://github.com/pew-pew-team/http-factory/workflows/tests/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/pew-pew-team/http-factory/actions\"\u003e\u003cimg src=\"https://github.com/pew-pew-team/http-factory/workflows/codestyle/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/pew-pew-team/http-factory/actions\"\u003e\u003cimg src=\"https://github.com/pew-pew-team/http-factory/workflows/security/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/pew-pew-team/http-factory/actions\"\u003e\u003cimg src=\"https://github.com/pew-pew-team/http-factory/workflows/static-analysis/badge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# HTTP Factory\n\nA set of drivers for encoding HTTP responses and decoding HTTP requests.\n\n## Installation\n\nPewPew HTTP Factory is available as Composer repository and can be installed\nusing the following command in a root of your project:\n\n```bash\n$ composer require pew-pew/http-factory\n```\n\nMore detailed installation [instructions are here](https://getcomposer.org/doc/01-basic-usage.md).\n\n## Usage\n\n### Decoder\n\n```php\n// Symfony Request\n$request = new \\Symfony\\Component\\HttpFoundation\\Request();\n\n// Requests Factory\n$requests = new \\PewPew\\HttpFactory\\RequestDecoderFactory([\n    new \\PewPew\\HttpFactory\\Driver\\JsonDriver(),\n]);\n\n$payload = $requests\n    -\u003ecreateDecoder($request) // Detect passed \"content-type\" header and\n                              // create decoder if available.\n    ?-\u003edecode($request-\u003egetContent(true));   // Decode request body.\n```\n\n### Encoder\n\n```php\n// Symfony Request\n$request = new \\Symfony\\Component\\HttpFoundation\\Request();\n\n// Responses Factory\n$responses = new \\PewPew\\HttpFactory\\ResponseEncoderFactory([\n    new \\PewPew\\HttpFactory\\Driver\\JsonDriver(),\n]);\n\n$response = $responses\n    -\u003ecreateEncoder($request) // Detect passed \"accept\" header and create\n                              // encoder if available.\n    ?-\u003eencode(['some' =\u003e 'any'], 200);  // Encode payload and create response.\n```\n\n### Symfony Integration\n\nAdd the bundle to your `bundles.php` file:\n\n```php\n// bundles.php\nreturn [\n    // ...\n    PewPew\\HttpFactory\\HttpFactoryBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\nUse `ResponseEncoderFactoryInterface` and `RequestDecoderFactoryInterface` \nin your services:\n\n```php\nuse PewPew\\HttpFactory\\ResponseEncoderFactoryInterface;\nuse Symfony\\Component\\HttpFoundation\\Response;\nuse Symfony\\Component\\HttpFoundation\\Request;\n\nfinal readonly class ExampleController\n{\n    public function __construct(\n        private ResponseEncoderFactoryInterface $responses,\n    ) {}\n    \n    public function someAction(Request $request): Response \n    {\n        $encoder = $this-\u003eresponses-\u003ecreateEncoder($request);\n        \n        if ($encoder === null) {\n            throw new \\Symfony\\Component\\HttpFoundation\\Exception\\BadRequestException(\n                'Unsupported \"accept\" request header',\n            );\n        }\n        \n        return $encoder-\u003eencode([\n            'status' =\u003e 'ok'\n        ], Response::HTTP_OK);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpew-pew-team%2Fhttp-factory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpew-pew-team%2Fhttp-factory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpew-pew-team%2Fhttp-factory/lists"}