Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haruncpi/http
Simple HTTP client for PHP
https://github.com/haruncpi/http
curl http-client php php-curl-library php-http-client
Last synced: about 1 month ago
JSON representation
Simple HTTP client for PHP
- Host: GitHub
- URL: https://github.com/haruncpi/http
- Owner: haruncpi
- Created: 2022-03-12T12:37:16.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-22T11:07:52.000Z (over 1 year ago)
- Last Synced: 2024-10-25T19:59:37.914Z (2 months ago)
- Topics: curl, http-client, php, php-curl-library, php-http-client
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Simple HTTP client for PHP
Install
```
composer require haruncpi/http
```Import class
```php
use Haruncpi\Http\Http;
```### GET request
```php
$url = "https://jsonplaceholder.typicode.com/comments";
$data = [ 'postId' => 1 ];$response = HTTP::get( $url, $data );
```
### POST request
```php
$url = "https://jsonplaceholder.typicode.com/posts";
$data = [ 'title' => 'This is post title' ];$response = HTTP::post( $url, $data );
```### More options
```php
$response = HTTP::get( $url, $data, $headers, $curlOptions );
$response = HTTP::post( $url, $data, $headers, $curlOptions );
```### Useful methods
```php
$response->getStatusCode(); // to get response code
$response->getHeaders(); // to get all headers as array
$response->getHeader($name); // to get specific header
$response->getBody(); // to get raw response body
$response->getJson(); // to get body as assoc array
$response->getObject(); // to get body as object
```