Thanzex's avatar

Proxy requests to other service

Hi! I'm fairly new to Laravel, I am wondering if it would be possible to expose a route to proxy traffic to another service outside of Laravel. Ideally I could still get authn/authz but don't have to recreate all the interface to the external service.

The proxy should handle HTTP and Websocket requests alike

                Laravel                      
             ┌───────────┐                   
             │           │                   
┌──────┐     │ ┌───────┐ │                   
│ User ├─┬───┤ │ Route │ │         Service   
└──────┘ │   │ └───────┘ │      ┌───────────┐
       ▲ │   │           │      │           │
       │ │   │ ┌───────┐ │      │           │
       │ └───┼─┤ Proxy ├─┼─────►│           │
       └─────┼─┤       ├─┼──────┤           │
             │ └───────┘ │      │           │
             │           │      └───────────┘
             └───────────┘                         

I could not find anything related to this and the only discussion in this forum that touches this problem is from 6 years ago with no reply.

0 likes
4 replies
martinbean's avatar

@thanzex What’s the problem you’re actually trying to solve? Why have a Laravel app, if it’s just going to hand off requests to something else?

Thanzex's avatar

@martinbean The app already exists and is fairly big and complex, for a new feature I need to interface via HTTP and Websockets to another service.

This external service already exposes all the APIs I need, but the users need to be able to access it from the main Laravel app.

If possible I'd like to not have to re-implement the API surface just to pass it along, hence the need for a proxy route. This way the users can access the external service features from the app, along with the necessary authentication and authorization, with minimal impact on the actual codebase

martinbean's avatar

@Thanzex I’d just proxy this at the web server level (i.e. Apache, nginx, etc). Otherwise you’re booting a full stack framework (Laravel) and occupying a PHP thread… just to pass the request somewhere else. So you can avoid that overhead and just have the web server proxy the request instead.

Thanzex's avatar

@martinbean Occupying a thread is not a problem, along with other performance considerations. While i do appreciate your support and pragmatic approach unfortunately this is not a valid solution.

The proxied endpoint still needs authentication and authorization coming from Laravel, this along with other considerations about the general application setup require the proxying be done via Laravel.

I have no doubt this can be done in PHP, and possibly out there there's an already implemented Laravel solution that I have not been able to find. If anything of the sort comes to mind, I'd be happy to hear about it

Please or to participate in this conversation.