4 years ago

Make internal API requests from Laravel to separate Lumen instance?

Posted 4 years ago by tag

Here's what I want to do:

  1. I want to create a simple REST API powered by Lumen, in a non-web accessible directory

  2. I want a separate Laravel project (living on the same server) to be a client that consumes the API.

  3. I want to consume that API via a common REST interface e.g. API::get(/league/4/players);

  4. I DON'T want to make actual HTTP requests, because I don't want the overhead, the API won't even be HTTP accessible, and I want Lumen to return Eloquent models instead of JSON so that it's far easier for me to pass those models through to blade for rendering.

  5. EVENTUALLY I might make the lumen API web accessible with authentication so that you can set Accept headers to request application/json, but for now I want it to be internal only, and return native PHP code to Laravel.

  6. Also eventually, I might move the Laravel client to a separate server on the same cluster, at which point I will want to enable HTTP requests via the internal network, which is why I want to make internal requests through an actual URI schema, so that I don't have to change anything. That is, I'll just hook up another API driver that actually makes HTTP requests and asks for JSON, and I never have to change any of the API::get('.....') calls.

So is there a way to do something like this between a separate Lumen and Laravel project?


Essentially I would create a request object that mocks the URI and request method in Laravel, but invoke that via the Lumen codebase's route dispatcher. Is it as simple as that, or do I need to find a way to get Lumen to go through it's boot process?

Please sign in or create an account to participate in this conversation.