{"id":39856986,"url":"https://github.com/dmt-software/http-client-middleware","last_synced_at":"2026-01-18T13:52:56.174Z","repository":{"id":56970336,"uuid":"466420238","full_name":"dmt-software/http-client-middleware","owner":"dmt-software","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-30T08:21:39.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-12T11:44:38.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dmt-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"publiccode":null,"codemeta":null}},"created_at":"2022-03-05T10:25:42.000Z","updated_at":"2024-08-29T13:57:47.000Z","dependencies_parsed_at":"2024-08-29T15:19:06.729Z","dependency_job_id":"924a7302-10f8-470e-9f8c-522b87e24c40","html_url":"https://github.com/dmt-software/http-client-middleware","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.26315789473684215","last_synced_commit":"2a4d8975196ddcea9da65a6801e6fca1298076dd"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/dmt-software/http-client-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fhttp-client-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fhttp-client-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fhttp-client-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fhttp-client-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmt-software","download_url":"https://codeload.github.com/dmt-software/http-client-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmt-software%2Fhttp-client-middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28537281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-18T13:52:55.978Z","updated_at":"2026-01-18T13:52:56.119Z","avatar_url":"https://github.com/dmt-software.png","language":"PHP","readme":"# Http Client Middleware\n\nUnfortunately [psr-15](https://www.php-fig.org/psr/psr-15/), the recommendation how to handle incoming server request, \ndoes not cover how to deal with an outgoing request or a client response.\n \nThis package solves that problem.\n\n## Installation\n`composer require dmt-software/http-client-middleware`\n\n## Usage\n\n```php\nuse DMT\\Http\\Client\\RequestHandler;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestInterface;\n\n/** @var ClientInterface $client */\n$handler = new RequestHandler($client);\n$response = $handler-\u003ehandle($request);\n \nif ($response-\u003egetStatusCode() === 200) {\n   // process the response\n}\n```\n\n### Middleware\n\nMiddleware can be used to process a request before it is sent to the server by the client or to handle the response,\nfor instance to apply authentication, store a login cookie or log the response.\n\n```php\nuse DMT\\Http\\Client\\MiddlewareInterface;\nuse DMT\\Http\\Client\\RequestHandlerInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Psr\\Http\\Message\\RequestInterface;\n\n/**\n * Apply basic authentication header to the request\n */\nclass BasicAuthMiddleware implements MiddlewareInterface\n{\n    private string $user = 'user';\n    private string $pass = '*****';\n    \n    public function process(RequestInterface $request, RequestHandlerInterface $handler): ResponseInterface\n    {\n        $request = $request-\u003ewithHeader(\n            'Authorization', sprintf('Basic %s', base64_encode(\"$this-\u003euser:$this-\u003epass\")) \n        );\n        \n        return $handler-\u003ehandle($request);\n    }\n}\n```\n\nTo enable middleware simply add these to the request handler.  \n\n```php\nuse DMT\\Http\\Client\\RequestHandler;\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestInterface;\n\n/** @var ClientInterface $client */\n$handler = new RequestHandler(\n    $client,\n    $basicAuthMiddleware,\n    $otherMiddleware,\n);\n$response = $handler-\u003ehandle($request);\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmt-software%2Fhttp-client-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmt-software%2Fhttp-client-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmt-software%2Fhttp-client-middleware/lists"}