2
votes

I have a Laravel app that makes a request to my Lumen API and passes a parameter to the HTTP header using GuzzleHttp\Client.

Below is the relevant code for the request made by Laravel app:

public function getJson($url) {

        $client = new Client;

        $header =  [
            'admin_user_id' => 2,
        ];

        $response = $client->request('GET', $url , [
            'headers' => $header
        ]);

        return $response->getBody();
    }

Then in my Lumen API, I try to access parameter value from http header as below:

use Illuminate\Http\Request;

class ProductController extends Controller {

    public function fetch_all(Request $request) {

            return $user_id = $request->header('admin_user_id');
      }
}

However, $request->header('admin_user_id'); doesn't seem to be returning any value.

1
What does it return? Do you get any error?Sven Hakvoort
No value is returned. I did not get any error message.WorkarP

1 Answers

2
votes

I would first verify that the API route is being hit and possibly dump all the request headers out to ensure your request is being sent to you Lumen API with the correct headers.

Also of note, if the header contains underscores, it is possible that the webserver is dropping that header. I believe nginx does this by default. Here is a link to a SO question on the subject: https://stackoverflow.com/a/22856867/7965016.

When using custom headers I usually stick with the widely accepted format of x-custom-header or in your case x-admin-user-id.