PHP code example of softok2 / api-client-wrapper

1. Go to this page and download the library: Download softok2/api-client-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

softok2 / api-client-wrapper example snippets




class Auth implements ClientResourceInterface
{
    public function __construct(protected RestClientInterface $client)
    {
    }

    /**
     * Retrieve the 'slug' to hook this class into global service client...
     */
    public static function getSlug(): string
    {
        return strtolower('Auth');
    }
}



    public function login(array $data): mixed
    {
        return $this->client->post('/login', $data)
    }



    public function login(array $data): mixed
    {
        return $this->client->post('/login', $data)
    }



class AuthController extends Controller
{
    public function index(RestClientInterface $client)
    {
        
        $data = [
            'user' => request('user'),
            'password' => request('password'),
        ]
        
        try{
         
            $token = $this->client->auth->login($data);

            // Storage token and redirect ...

        }catch(Exception $exception){
           // Handle custom errors 
        }
    }
}
bash
php artisan vendor:publish --provider="Softok2\RestApiClient\Providers\ServiceProvider" --tag="config"
bash
php artisan make:apic Auth