https://github.com/soltancode/sendrequest
Simple package for Laravel that makes it easy to send HTTP requests and integrate with web APIs.
https://github.com/soltancode/sendrequest
api curl guzzle http-client httpclient laravel php requests rest
Last synced: 20 days ago
JSON representation
Simple package for Laravel that makes it easy to send HTTP requests and integrate with web APIs.
- Host: GitHub
- URL: https://github.com/soltancode/sendrequest
- Owner: soltancode
- License: mit
- Created: 2022-09-15T15:23:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-24T11:18:04.000Z (over 2 years ago)
- Last Synced: 2025-04-09T15:07:43.151Z (21 days ago)
- Topics: api, curl, guzzle, http-client, httpclient, laravel, php, requests, rest
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# SendRequest
Simple package for Laravel Framework that makes it easy to send HTTP requests and integrate with web APIs.
[](https://packagist.org/packages/soltancode/send-request)
[](https://packagist.org/packages/soltancode/send-request)
[](https://packagist.org/packages/soltancode/send-request)
[](https://packagist.org/packages/soltancode/send-request)
[](https://github.com/soltancode/SendRequest/blob/main/LICENSE)## Installation
```
composer require soltancode/send-request
```## Usage
#### If you use it as class (facade), import this:
```php
use Soltancode\SendRequest\Facades\SendRequest;
```#### GET Request:
```php
// $baseUrl = "https://dummyjson.com";
// $service = "/products/1";# Using as class:
SendRequest::get($baseUrl, $service);# Using as helper:
sendRequest()->get($baseUrl, $service)
```#### GET Request with params:
```php
// $baseUrl = "https://dummyjson.com";
// $service = "/products/1";
// $params = [
// 'q' => 'phone'
// ];# Using as class:
SendRequest::get($baseUrl, $service, $params); # https://dummyjson.com/products/search?q=phone# Using as helper:
sendRequest()->get($baseUrl, $service, $params); # https://dummyjson.com/products/search?q=phone
```#### POST Request with params:
```php
// $baseUrl = "https://api.example.com";
// $service = "/login";# Using as class:
SendRequest::post($baseUrl, $service, [
'username' => 'myusername',
'password' => 'mypassword'
]);# Using as helper:
sendRequest()->post($baseUrl, $service, [
'username' => 'myusername',
'password' => 'mypassword'
]);
```#### PUT Request with params:
```php
// $baseUrl = "https://api.example.com";
// $service = "/users/1";# Using as class:
SendRequest::put($baseUrl, $service, [
'first_name' => 'John',
'last_name' => 'Doe'
]);# Using as helper:
sendRequest()->put($baseUrl, $service, [
'first_name' => 'John',
'last_name' => 'Doe'
]);
```#### PATCH Request with params:
```php
// $baseUrl = "https://api.example.com";
// $service = "/users/1";# Using as class:
SendRequest::patch($baseUrl, $service, [
'first_name' => 'John'
]);# Using as helper:
sendRequest()->patch($baseUrl, $service, [
'first_name' => 'John'
]);
```#### DELETE Request with params:
```php
// $baseUrl = "https://api.example.com";
// $service = "/users";# Using as class:
SendRequest::delete($baseUrl, $service, [
'id' => 'John'
]);# Using as helper:
sendRequest()->delete($baseUrl, $service, [
'id' => 'John'
]);
```### Timeout
The timeout method may be used to specify the maximum number of seconds to wait for a response:
```php
$response = sendRequest()->timeout(3)->post(/* ... */);
```## Other Packages
[ReturnResponse](https://github.com/soltancode/ReturnResponse) - It's a return helper for showing standard json responses.## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please make sure to update tests as appropriate.
## License
[MIT](https://github.com/soltancode/SendRequest/blob/main/LICENSE)