Search code examples
pythonrestgraphqlreasonrescript

How to make requests from back-end to another server on user’s localhost


I’ve got a standard client-server set-up with ReScript (ReasonML) on the front-end and a Python server on the back-end.

The user is running a separate process on localhost:2000 that I’m connecting to from the browser (UI). I can send requests to their server and receive responses.

Now I need to issue those requests from my back-end server, but cannot do so directly. I’m assuming I need some way of doing it through the browser, which can talk to localhost on the user’s computer.

  1. What are some conceptual ways to implement this (ideally with GraphQL)? Do I need to have a subscription or web sockets or something else?

  2. Are there any specific libraries you can recommend for this (perhaps as examples from other programming languages)?


Solution

  • I think the easiest solution with GraphQL would be to use Subscriptions indeed, the most common Rescript GraphQL clients already have such a feature, at least ReasonRelay, Reason Apollo Hooks and Reason-URQL have it.