{"id":26570750,"url":"https://github.com/activ8-developers/purli","last_synced_at":"2025-03-22T22:19:14.218Z","repository":{"id":57004016,"uuid":"64547235","full_name":"ACTIV8-Developers/Purli","owner":"ACTIV8-Developers","description":"Purli (PHP Url Interface) is lightweight library with object-oriented interface for sending HTTP requests.","archived":false,"fork":false,"pushed_at":"2023-06-18T10:32:37.000Z","size":35,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T14:45:22.907Z","etag":null,"topics":["api","curl","http","httpclient","php","purli","socket","webservices"],"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/ACTIV8-Developers.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":"2016-07-30T14:11:37.000Z","updated_at":"2023-06-18T10:31:52.000Z","dependencies_parsed_at":"2022-08-21T12:10:50.282Z","dependency_job_id":null,"html_url":"https://github.com/ACTIV8-Developers/Purli","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACTIV8-Developers%2FPurli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACTIV8-Developers%2FPurli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACTIV8-Developers%2FPurli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ACTIV8-Developers%2FPurli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ACTIV8-Developers","download_url":"https://codeload.github.com/ACTIV8-Developers/Purli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245026514,"owners_count":20549147,"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","curl","http","httpclient","php","purli","socket","webservices"],"created_at":"2025-03-22T22:19:13.116Z","updated_at":"2025-03-22T22:19:14.179Z","avatar_url":"https://github.com/ACTIV8-Developers.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Purli\n=\n[![DUB](https://img.shields.io/dub/l/vibe-d.svg)](http://opensource.org/licenses/MIT)\n[![Version](https://img.shields.io/badge/version-1.0.0-green.svg)](https://github.com/Kajna/Purli/releases)\n\n\nPurli (PHP Url Interface) is the lightweight library with the object-oriented interface for sending HTTP requests. \n\nInstalling\n=\nThis package is available via [Composer](https://getcomposer.org/):\n\n```json\n{\n  \"require\": {\n    \"kajna/purli\": \"dev-master\"\n  }\n}\n```\n\nUsage examples\n=\n\n#### Fetching data using GET method and CURL handler\nMinimal example, Purli by default uses CURL handler if available otherwise fallback to the socket.\n```php\ntry {\n    $purli = (new \\Purli\\Purli())\n        -\u003eget('http://www.example.com')\n        -\u003eclose();\n\n    $response = $purli-\u003eresponse();\n\n    echo $response-\u003easText();\n} catch(\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n#### Fetching data using GET method and socket handler\nIf explicitly set Purli will use PHP sockets to make requests regardless if CURL is installed or not\n```php\ntry {\n    $purli = (new \\Purli\\Purli(\\Purli\\Purli::SOCKET))\n            -\u003eget('http://example.com')\n            -\u003eclose();\n    \n    $response = $purli-\u003eresponse();\n    \n    echo $response-\u003easText();\n} catch(\\Exception $e) {\n\techo $e-\u003egetMessage();\n}\n```\n\n#### Fetching data using POST method\n```php\ntry {\n    $data = array('foo' =\u003e 'bar');\n\n    $purli = (new \\Purli\\Purli())\n        -\u003esetParams($data)\n        -\u003epost('http://www.example.com')\n        -\u003eclose();\n\n    $response = $purli-\u003eresponse();\n\n    print_r($response-\u003easText());\n} catch(\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n#### Sending and receiving XML data using POST method\n\n```php\ntry {\n    $data = '\u003croot\u003e\u003cfoo\u003ebar\u003c/foo\u003e\u003c/root\u003e';\n\n    $purli = (new \\Purli\\Purli())\n        -\u003esetUserAgent('curl 7.16.1 (i386-portbld-freebsd6.2) libcurl/7.16.1 OpenSSL/0.9.7m zlib/1.2.3')\n        -\u003esetHeader('Content-Type', 'text/xml')\n        -\u003esetParams($data)\n        -\u003epost('http://www.example.com')\n        -\u003eclose();\n\n    $response = $purli-\u003eresponse();\n\n    print_r($response-\u003easArray());\n} catch(\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n#### Sending and receiving JSON data using PUT method\n```php\ntry {\n    $data = array('foo' =\u003e 'bar');\n    $json = json_encode($data);\n    \n    $purli = (new \\Purli\\Purli(\\Purli\\Purli::SOCKET))\n            -\u003esetConnectionTimeout(3)\n            -\u003esetHeader('Content-Type', 'application/json')\n            -\u003esetParams($json)\n            -\u003eput('http://www.example.com')\n            -\u003eclose();\n    \n    $response = $purli-\u003eresponse();\n    \n    print_r($response-\u003easObject());\n} catch(\\Exception $e) {\n\techo $e-\u003egetMessage();\n}\n```\n\n#### Using proxy server to make request\n```php\ntry {\n    $purli = (new \\Purli\\Purli());\n    \n    $purli\n        -\u003esetProxy(PROXY_ADDRESS, PROXY_PORT)\n        -\u003eget('http://www.example.com')\n        -\u003eclose();\n\n    $response = $purli-\u003eresponse();\n\n    echo $response-\u003easText();\n} catch(\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n#### Setting custom CURL option\nIf CURL extension is installed by default Purli will use it, \nyou can always get CURL handler object and set custom option if more flexibility is needed\n```php\ntry {\n    $purli = (new \\Purli\\Purli());\n    \n    if ($purli-\u003egetHandlerType() === \\Purli\\Purli::CURL) {\n        curl_setopt($purli-\u003egetHandler(), CURLOPT_TIMEOUT, 10);\n    }\n    \n    $purli\n        -\u003eget('http://www.example.com')\n        -\u003eclose();\n\n    $response = $purli-\u003eresponse();\n\n    echo $response-\u003easText();\n} catch(\\Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\nRunning tests\n=\nPurli uses [PHPUnit](https://phpunit.de/) for testing, navigate to project root directory and run command:\n```$xslt\ncd tests\nphpunit\n```\n\nAuthor\n=\nMilos Kajnaco \nmilos@caenazzo.com\n\nContributors\n=\nNemanja Nikolic\nnemanja@massvision.net\n\nLicence\n=\nPurli is released under the [MIT](http://opensource.org/licenses/MIT) public license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factiv8-developers%2Fpurli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factiv8-developers%2Fpurli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factiv8-developers%2Fpurli/lists"}