Abstracting a child process's stdin/stdout over a HTTP endpoint, idiomatically?

I've got a bit of a handle on actix-web. Basically I have my code running a child process, that takes in JSON messages and does things (it's a language server if you're curious), and then returns a JSON message.

Where should I start in trying to expose this child process over a HTTP endpoint? How do I think about the process blocking other processes, or asynchronous processing - and futures? There seems to be a lot of ways out there and I'm really more looking at a jumping off point. If another web framework makes this easier, I'd use it too!

Actix internally uses Tokio, so you can use Tokio's process module to asynchronously spawn child processes. Then the easiest method is to use Command::output to get the full output of the command and then return it from the function.

If you are interested in streaming the response while the child is still running, that's possible too but a bit more cumbersome.

Note: I have linked to Tokio 0.2's documentation as actix uses Tokio 0.2.

1 Like

Would streaming require the use of something like WebSockets?

No, as far as I understand you can return some sort of Body or Stream type as your response. It would be possible to write a stream that yielded the data as the child process gave it to you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.