New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

soltancode/send-request

Simple package for Laravel that makes it easy to send HTTP requests and integrate with web APIs.
2,551 2
Install
composer require soltancode/send-request
Latest Version:v2.0.0
PHP:^8.0
Laravel:9
License:MIT
Last Updated:Nov 24, 2022
Links: GitHub  ·  Packagist
Maintainer: soltancode

SendRequest

Simple package for Laravel Framework that makes it easy to send HTTP requests and integrate with web APIs.

Packagist Version Packagist Stars Packagist Downloads Packagist PHP Version Support Packagist License

Installation

composer require soltancode/send-request

Usage

If you use it as class (facade), import this:
use Soltancode\SendRequest\Facades\SendRequest;
GET Request:
// $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:
// $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:
// $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:
// $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:
// $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:
// $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:

$response = sendRequest()->timeout(3)->post(/* ... */);

Other Packages

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

Related Packages

soltancode/return-response

Simple package for returning standard json responses for Laravel.

2,535 5
givebutter/laravel-keyable

Add API keys to your Laravel models

176,380 189
cline/relay

A modern, attribute-driven HTTP client for PHP

10,316 0
league/fractal

Handle the output of complex data structures ready for API output.

71,330,713 3,543
pixelfed/fractal

Handle the output of complex data structures ready for API output.

97,990 0

Version History

Version Released PHP Laravel License
v2.0.0 ^8.0 ^9.0 MIT
v1.0.0 ^7.3|^8.0 ^9.0 MIT