Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lablnet/php-http-client
http-client is the php package. It provides the ability to manage and parse request object. It also provides support for HTTP client transactions via cURL.
https://github.com/lablnet/php-http-client
classes client free http mit oop package php psr-7
Last synced: 2 months ago
JSON representation
http-client is the php package. It provides the ability to manage and parse request object. It also provides support for HTTP client transactions via cURL.
- Host: GitHub
- URL: https://github.com/lablnet/php-http-client
- Owner: lablnet
- License: mit
- Created: 2019-01-24T06:21:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-23T09:24:34.000Z (almost 5 years ago)
- Last Synced: 2024-11-13T05:58:22.410Z (3 months ago)
- Topics: classes, client, free, http, mit, oop, package, php, psr-7
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 11
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP HTTP Client
http-client is the php package. It provides the ability to manage and parse request object. It also provides support for HTTP client transactions via cURL.## Requirement
- PHP
- Composer## install
run this command
``` composer require lablnet/http-client ```## BASIC USAGE
### The request object, GET example
Let's use a GET request with the URL '/index.php?var=value'```php
getQuery('var');
//it print the get request
var_dump($var);
```
### The request object, POST example
Let's use a POST request.
```php
// Get the value of $_POST['id']
if ($request->isPost()) {
$id = $request->getPost('id');
}
```
### Creating a response object
```php
//Response
$config = [
'code' => 200,
'headers' => [
'Content-Type' => 'text/html'
]
];$response = new Lablnet\Response($config);
$response->setBody('This is a plain text file.');$response->send();
```
### Simple response redirect
```php
//Redirect to other page/site.
(new Lablnet\Redirect('https://zestframework.xyz/'));
```### Using the cURL client
```php
//Using the cURL client
//Send request to https://zestframework.xyz login page with post method
$request = $request->curl("https://zestframework.xyz/account/login/action","POST");
//Set transfer and return header
$request->setReturnHeader(true)->setReturnTransfer(true);
//Set the fields
$request->setFields([
'username' => 'your-username',
'password' => 'your-password'
]);
//Send the request
$request->send();
// return => 200
$statusCode = $request->getCode();
// Display the body of the returned response
echo "
".$request->getBody();
```