{"id":33955542,"url":"https://github.com/sfn/psr7-httpclient","last_synced_at":"2026-04-09T04:31:03.756Z","repository":{"id":57048450,"uuid":"99681967","full_name":"sfn/psr7-httpclient","owner":"sfn","description":"A simple PSR7 client","archived":false,"fork":false,"pushed_at":"2017-08-26T17:52:34.000Z","size":26,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-14T08:52:04.355Z","etag":null,"topics":["http-client","php7","psr-17","psr-7","psr7-httpclient","rest-api","rest-client"],"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/sfn.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":"2017-08-08T10:44:02.000Z","updated_at":"2022-02-12T14:23:12.000Z","dependencies_parsed_at":"2022-08-23T19:10:32.359Z","dependency_job_id":null,"html_url":"https://github.com/sfn/psr7-httpclient","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sfn/psr7-httpclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfn%2Fpsr7-httpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfn%2Fpsr7-httpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfn%2Fpsr7-httpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfn%2Fpsr7-httpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sfn","download_url":"https://codeload.github.com/sfn/psr7-httpclient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sfn%2Fpsr7-httpclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31586403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["http-client","php7","psr-17","psr-7","psr7-httpclient","rest-api","rest-client"],"created_at":"2025-12-12T20:03:44.055Z","updated_at":"2026-04-09T04:31:03.750Z","avatar_url":"https://github.com/sfn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sfn HttpClient\n\n[![Latest Version](https://img.shields.io/packagist/v/sfn/httpclient.svg)](https://packagist.org/packages/sfn/httpclient)\n[![MIT license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/sfn/psr7-httpclient/master/LICENSE)\n[![PHP](https://img.shields.io/badge/PHP-7.0%2B-777bb4.svg)](http://www.php.net/)\n\nJust a simple and little PSR7 client.\nIt is still a work-in-progress but, more or less, it works.\n\n## Table of Contents\n* [Requirements](#requirements)\n* [Installation](#installation)\n    * [Zend Diactoros support](#zend-diactoros-support)\n    * [Guzzle support](#guzzle-support)\n    * [Slim support](#slim-support)\n* [Usage](#usage)\n    * [Create a client instance](#create-a-client-instance)\n    * [Send a request](#send-a-request)\n    * [Methods for REST API](#helper-methods-for-rest-api)\n    * [Base URI](#base-uri)\n* [To-do](#to-do)\n* [License](#license)\n\n## Requirements\n* PHP 7.0 or higher\n* `php-curl` or `allow_url_fopen` set to true\n* A [PSR7](http://www.php-fig.org/psr/psr-7/) implementation.\n\n`Sfn\\HttpClient` needs a PSR-7 implementation. It supports\n[Zend Diactoros](https://github.com/zendframework/zend-diactoros),\n[Guzzle](https://github.com/guzzle/psr7) and\n[Slim](https://github.com/slimphp/Slim-Http) at the moment.\n\nOf course you can write your own HTTP Factory implementation for any PSR-7 implementation,\nlook [here](https://github.com/http-interop/http-factory-diactoros/tree/master/src)\nfor PSR-17 Http Factory interfaces.\n\n## Installation\nInstall using [Composer](https://getcomposer.org/).\n```\ncomposer require sfn/httpclient\n```\n\n#### Zend Diactoros support\n```\ncomposer require http-interop/http-factory-diactoros\n```\n\n#### Guzzle support\n```\ncomposer require http-interop/http-factory-guzzle\n```\n\n#### Slim support\n```\ncomposer require http-interop/http-factory-slim\n```\n\n## Usage\n### Create a client instance\nWith the `ClientFactory::make()` method you can create the correct instance\nof the client. If it finds curl installed, it creates a client with a curl\nbackend, otherwise it create a client who send request via php's\n`file_get_contents`.\n\n`ClientFactory::make()` accepts an associative array with the client\nconfiguration. You must specify at least your PSR-17 HTTP Factory implementation.\n[Here](PARAMETERS.md#client-configuration-parameters) you can find the complete\nlist of parameters in you can set in the configuration array.\n\n```php\n// Zend Diactoros\n$config = [\n    'requestfactory'  =\u003e new Http\\Factory\\Diactoros\\RequestFactory,\n    'responsefactory' =\u003e new Http\\Factory\\Diactoros\\ResponseFactory,\n    'urifactory'      =\u003e new Http\\Factory\\Diactoros\\UriFactory,\n];\n\n// Guzzle\n$config = [\n    'requestfactory'  =\u003e new Http\\Factory\\Guzzle\\RequestFactory,\n    'responsefactory' =\u003e new Http\\Factory\\Guzzle\\ResponseFactory,\n    'urifactory'      =\u003e new Http\\Factory\\Guzzle\\UriFactory,\n];\n\n// Slim\n$config = [\n    'requestfactory'  =\u003e new Http\\Factory\\Slim\\RequestFactory,\n    'responsefactory' =\u003e new Http\\Factory\\Slim\\ResponseFactory,\n    'urifactory'      =\u003e new Http\\Factory\\Slim\\UriFactory,\n];\n\n$client = Sfn\\HttpClient\\ClientFactory::make($config);\n```\n\n### Send a request\nFirst of all, you must create a request with your preferred\n`Psr\\Http\\Message\\RequestInterface` implementation. Then you simply call the\n`send()` method of the client.\n```php\n$request = (new Zend\\Diactoros\\Request())\n    -\u003ewithUri(new Zend\\Diactoros\\Uri('http://api.example.com/path'))\n    -\u003ewithMethod('GET')\n    -\u003ewithAddedHeader('Content-Type', 'application/json');\n\n$response = $client-\u003esend($request); // Return a ResponseInterface\n```\n\n### Helper methods for REST API\nThere are `get()`, `post()`, `put()`, `delete()` and `patch()` helper methods.\nYou can pass a second parameter, with an array of options.\n[Here](PARAMETERS.md#request-parameters) you can find a complete list of request\nparameters.\n\n```php\n// GET request\n$response = $client-\u003eget('http://api.example.com/path');\n\n// POST request\n$response = $client-\u003epost(\n    'http://api.example.com/path',\n    ['body' =\u003e http_build_query(['foo' =\u003e 'bar'])]\n);\n```\n\n### Base URI\nYou can also specify a base uri in the client configuration.\n```php\n$config = [\n    'requestfactory'  =\u003e new Http\\Factory\\Diactoros\\RequestFactory,\n    'responsefactory' =\u003e new Http\\Factory\\Diactoros\\ResponseFactory,\n    'urifactory'      =\u003e new Http\\Factory\\Diactoros\\UriFactory,\n    'baseuri'         =\u003e 'http://api.example.com'\n];\n$client = Sfn\\HttpClient\\ClientFactory::make($config);\n\n// GET request\n$response = $client-\u003eget('path'); // GET http://api.example.com/path\n```\n\n## To-Do\n* Cookies support\n* SSL authentication\n* Examples\n* Better documentation\n\n## License\n[MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfn%2Fpsr7-httpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsfn%2Fpsr7-httpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsfn%2Fpsr7-httpclient/lists"}