{"id":17846435,"url":"https://github.com/technicalguru/php-rest-client","last_synced_at":"2026-04-16T15:33:13.574Z","repository":{"id":57066163,"uuid":"312377100","full_name":"technicalguru/php-rest-client","owner":"technicalguru","description":"A PHP REST client","archived":false,"fork":false,"pushed_at":"2022-10-30T10:02:25.000Z","size":33,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-30T02:54:01.935Z","etag":null,"topics":["json","json-data","rest-api","rest-client","restapi"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/technicalguru.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}},"created_at":"2020-11-12T19:34:40.000Z","updated_at":"2021-06-19T11:55:34.000Z","dependencies_parsed_at":"2022-08-24T14:53:59.743Z","dependency_job_id":null,"html_url":"https://github.com/technicalguru/php-rest-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/technicalguru/php-rest-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalguru%2Fphp-rest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalguru%2Fphp-rest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalguru%2Fphp-rest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalguru%2Fphp-rest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/technicalguru","download_url":"https://codeload.github.com/technicalguru/php-rest-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalguru%2Fphp-rest-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31892325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"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":["json","json-data","rest-api","rest-client","restapi"],"created_at":"2024-10-27T21:39:56.391Z","updated_at":"2026-04-16T15:33:13.554Z","avatar_url":"https://github.com/technicalguru.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-rest-client\nA lightweight REST client based on php-curl.\n\n# License\nThis project is licensed under [GNU LGPL 3.0](LICENSE.md). \n\n# Installation\n\n## By Composer\n\n```\ncomposer install technicalguru/rest-client\n```\n\n## By Package Download\nYou can download the source code packages from [GitHub Release Page](https://github.com/technicalguru/php-rest-client/releases)\n\n# How to use\n\n## Creating a Request\n\nDepending on your intent, all you need is the URL and the body if required:\n\n```\nuse TgRestClient\\Request;\n\n$request = Request::get('https://www.example.com/endpoint');\n$request = Request::put('https://www.example.com/endpoint', $myObject);\n$request = Request::post('https://www.example.com/endpoint', $myObject);\n$request = Request::delete('https://www.example.com/endpoint/123');\n```\n\nRequest provides a static method for each of the HTTP methods: HEAD, GET, POST, PUT, PATCH, OPTIONS, DELETE.\n\n## Setting Request Headers\n\nAdditional headers for the request can be set like this:\n\n```\nuse TgRestClient\\Headers;\n\n// individual headers\n$request\n    -\u003esetHeader(Headers::AUTHORIZATION, 'Bearer 1234567890')\n    -\u003esetHeader(Headers::COOKIE,        'XSESSION=qwefjnqlkiu117o11ndn1');\n    \n// set multiple headers with a (key =\u003e value) array\n$request-\u003eaddHeaders($headers);\n```\n\n## The Request Body\n\nBy default, `Request` assumes your body needs to be of `application\\json` type. As such,\nthe implementation already knows how to build a JSON encoding and you can pass an object or\narray for your body. `Request` will automatically stringify. Same is valid for `application/x-www-form-urlencoded`\ncontent. However, you will need to set the `Content-Type` header accordingly:\n\n```\nuse TgRestClient\\Request;\nuse TgRestClient\\Headers;\n\n$parameters = array(\n    'name1' =\u003e 'value1',\n    'name2' =\u003e 'value2',\n);\n$request = Request::post($url, $parameters)\n    -\u003esetHeader(Headers::CONTENT_TYPE, Headers::TYPE_X_WWW_FORM_URLENCODED);\n```\n\n## Executing\n\nOnce you configured your request, you can simply execute it:\n\n```\n$response = $request-\u003eexecute();\n```\n\nThe execute call takes an optional argument - the number of seconds until the call times out. The default timeout is 5 seconds.\nThe method will return latest after this time and give you a `Response` object.\n\n## The Response\n\nThe response object returns everything you need to know about the result of your call:\n\n```\n$httpCode    = $response-\u003egetHttpCode();\n$bodyObject  = $response-\u003egetBody();\n$rawBody     = $response-\u003egetRawBody();\n$headerValue = $response-\u003egetHeader('Server');\n```\n\nThe `getBody()` method returns objects when the server returned a JSON-encoded body. Otherwise, you will get the\nraw body by this method too.\n\n## Defining Default Request Headers\n\nIt can be very exhausting to set the same request headers for each individual request over and over again. That's why\nyou can define default headers:\n\n```\nuse TgRestClient\\Headers;\n\n// Single header\nHeaders::setDefaultHeader('www.example.com', Headers::AUTHORIZATION, 'Bearer 1234567890');\n\n// or multiple\nHeaders::addDefaultHeaders('www.example.com', $myDefaultHeaders);\n```\n\nThe headers will be available for each request to www.example.com. However, you can override headers\nfor individual requests if required. Just set the header on the request object.\n\n## Executing Requests Simultaneously\n\nOne strength of the library is the ability to perform multiple requests at the same time:\n\n```\nuse TgRestClient\\Client;\nuse TgRestClient\\Request;\n\n// Build your request objects\n$request1  = Request::get($url1);\n$request2  = Request::get($url2);\n...\n\n// Create the client\n$client = new Client();\n\n// Add the requests to the client and get the Response objects\n$response1 = $client-\u003eaddCall($request1);\n$response2 = $client-\u003eaddCall($request2);\n...\n\n// Now execute all together\n$responses = $client-\u003erun();\n```\n\nPlease notice that the `Response` objects cannot be used before you called the `run()` method on the client.\n\nThe `run()` method again can take a timeout in seconds (which defaults to 5). It also returns an array of the `Response`\nobjects in the order of how you added them to the client. That means, the first response belongs to the very first request \nyou added, the seconds response to the second request you added, and so on.\n\nYou can also ask the `Response` object which `Request` it was executing:\n\n```\n$request1 = $responses[0]-\u003egetRequest();\n$request2 = $responses[1]-\u003egetRequest();\n```\n\n# Developer Remark\n\nThe PHP Unit test will require a [gorest.co.in](http://gorest.co.in) API token. Most tests will not be\nexecuted without this token stored in environment variable `GOREST_TOKEN`.\n\n# Contribution\nReport a bug, request an enhancement or pull request at the [GitHub Issue Tracker](https://github.com/technicalguru/php-rest-client/issues).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnicalguru%2Fphp-rest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnicalguru%2Fphp-rest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnicalguru%2Fphp-rest-client/lists"}