Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cleantalk/http-lib
Standalone HTTP library
https://github.com/cleantalk/http-lib
Last synced: about 1 month ago
JSON representation
Standalone HTTP library
- Host: GitHub
- URL: https://github.com/cleantalk/http-lib
- Owner: CleanTalk
- License: gpl-3.0
- Created: 2022-04-28T08:46:54.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-19T07:09:36.000Z (about 2 years ago)
- Last Synced: 2024-11-07T04:44:50.218Z (about 2 months ago)
- Language: PHP
- Size: 28.3 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cleantalk HTTP Requests
===================Standalone PHP HTTP Request library
### Description
This standalone library allowing you to use different HTTP-requests in easy way.
It could be simply merged into your project. Please, see "Usage" to learn more.### Features
- POST, GET HTTP-methods.
- Multiple requests.
- Asynchronous requests.
- Callback functions.
- CURL options support.
- Any combination of the above features.### Usage
Download and include the file into your project by using PSR-0 (autoload) or directly attaching the files with "include" instruction.
Use the following code to use the Request:$request = new Cleantalk\Common\HTTP\Request();
$request_result = $request
->setUrl('example.com')
->setData(['foo' => 'bar']])
->setPresets(['async', 'ssl']))
->request();
You can reuse once created object change it URL and callback functions any time:$another_request_result = $request
->setUrl($new_url)
->setCallback(
function ($response_content, $requested_url){
$processed_response_content = strreplace(
'Hello',
'Hey!',
$response_content
);
return $processed_response_content;
})
->request();
Or use a multiple async requests. This one will send asynchronous requests to example.com and exapme2.com wth custom user-agent and pass the response direct to the output buffer:$miltiple_request = new Cleantalk\Common\HTTP\Request();
$multiple_request_result = $request
->setUrl(['example.com', 'example2.com'])
->setData(['foo' => 'bar']])
->setPresets(['async']))
->setOptions([
CURLOPT_RETURNTRANSFER => fase, // CURL format is supported
'user-agent' => 'My custom User-Agent' // And user-friendly
])
->request();
## Presets
The lib is using presets which allow you to configure its behaviour.
Use 'setPresets()' method to set them.->setPresets([
'async',
'get',
'dont_follow_redirects'
])May use the following presets (you can combine them in any way you want):
+ dont_follow_redirects - ignore 300-family response code and don't follow redirects
+ get_code - getting only HTTP response code
+ async - async requests. Sends request and return 'true' value. Doesn't wait for response.
+ get - makes GET-type request instead of default POST-type
+ ssl - uses SSL
+ cache - allow caching for this request
+ retry_with_socket - make another request with socket if cURL failed to retrieve data## Options
If you need to precise tune you could use 'setOptions' method:->setOptions([
CURLOPT_RETURNTRANSFER => fase, // CURL format is supported
'user-agent' => 'My custom User-Agent' // And user-friendly
])
It supports any cURL type options(learn more in [cURL documentation](https://www.php.net/curl_setopt)) and the following human-friendly:
+ timeout - maximum connection duration(int)
+ sslverify - verify host (bool)
+ sslcertificates - pass your own SSL certificate (string)
+ headers - any custom headers (array of strings)
+ user-agent - custom user-agent (string)## License
This library is open-sourced software licensed under the [GPLv3 license](http://www.gnu.org/licenses/gpl-3.0.html).