pickmap / service-request
A regular structure for sending requests from client to client
0.2.0
2024-01-20 11:49 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.2
- laravel/framework: 7.*|8.*|9.*|10.*|11.*
This package is not auto-updated.
Last update: 2024-09-28 15:08:28 UTC
README
If you work in a macro service structure or if you need a very light library to send and receive reposts in a simple service or application, this library will greatly help you.
Currently, it is only implemented to receive tokens from https://www.keycloak.org/, but you can complete it The best usage example is shown in this chart so that you can do the "Request To Service With Token" step with this library.
setp #1
composer require pickmap/service-request
setp #2
Define the following variables in your .env file
KEYCLOAK_CLIENT_ID=client-id KEYCLOAK_CLIENT_SECRET=keycloak-secret-key KEYCLOAK_USERNAME=usernameOrEmail KEYCLOAK_PASSWORD=password KEYCLOAK_LOGIN_URL='https://...openid-connect/token?grant_type=password'
setp #2
In any class you want to be equipped to send a request like a model or controller, do the following
class sample { use ServiceRequest; public function aMethod() { self::requestPost('https:://service.com/list'); } }
You can access these methods separately
//If $refreshToken is equal to true, the token will be refreshed regardless of the cache self::getToken($refreshToken); self::requestToKeyCloak(); /* Authorization is set in all tokens, but with this method, it is overwritten by the third parameter of post and get methods. */ self::HeadersProcess($newHeader); self::requestPost(string $url,array $data = [],$headers = []); self::requestGet(string $url,array $data = [],$headers = []);