PHP code example of pathum4u / api_request

1. Go to this page and download the library: Download pathum4u/api_request 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/ */

    

pathum4u / api_request example snippets


php artisan vendor:publish



return [
    'user' => [
        'base_uri' => env('USER_SERVICE_URI'),
        'secret' => env('USER_SERVICE_SECRET')
    ],

    'notification' => [
        'base_uri' => env('NOTIFICATION_SERVICE_URI'),
        'secret' => env('NOTIFICATION_SERVICE_SECRET')
    ],
];

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $allowedSecrets = explode(',', env('MY_SECRETS_TOKEN'));

        if (in_array($request->header('Secret'), $allowedSecrets)) {
            return $next($request);
        }

        // 
        return response()->json(['message' => 'unauthorized token'], 401);
    }