fintech-systems / laravel-api-helpers
Various helpers to make interacting with APIs easier
Fund package maintenance!
fintech-systems
Requires
- php: ^8.0
- illuminate/contracts: ^9.25
- spatie/laravel-package-tools: ^1.12
Requires (Dev)
- nunomaduro/collision: ^6.2
- orchestra/testbench: ^7.6
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.2
- spatie/laravel-ray: ^1.30
- vimeo/psalm: ^4.26
README
A helper library to facilitate working with APIs
API: Get, Post, Delete
public function get(string $url, array $header = [])
public function post(string $url, string|array $postFields, array $header = [])
public function delete(string $url, string|array $postFields = '', array $header = [])
Laravel API Helper Command - facilitates caching JSON API responses
Example:
class UserCommand extends LaravelApiHelpersCommand { /** * The name and signature of the console command. * * @var string */ protected $signature = 'api:get-users {--cached}'; ... /** * Execute the console command. * * @return int */ public function handle() { if ($file = $this->checkCachedFileExists()) { $this->info('A cached API result file was returned'); return $file; } $result = file_put_contents($this->cachedFile, Api::getUsers()); $this->info('The API command was successful'); return $result; }
Installation
You can install the package via composer:
composer require fintech-systems/laravel-api-helpers
Usage
WhatsApp to WHMCS phone number conversion
$api = new Api(); $result = $api->convertWhatsAppNumberToWhmcsPhoneNumber('27823096710'); expect($result)->toEqual('+27.82 309 6710'); $api = new Api(); $result = $api->convertWhatsAppNumberToWhmcsPhoneNumber('14085551234'); expect($result)->toEqual('+1.408-555-1234');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.