mooch
mooch2y ago

Proxying a Rust API using FFI?

I have a rust application that serves a rest api that runs in a container. I also have a deno cli that acts as a client for the api, among other things. A usecase came up where a user of the CLI would want to spin up the rust API for "testing" but will not have access to the api. For this use case, I would like to package the rust api with the deno cli as a library and add a command to the cli named something like serve, which starts the rust web server. The problem is that the deno cli already has its own serve command with its own rest api. Is it possible to hook the rust api up with the deno native http server?
1 Reply
AapoAlas
AapoAlas2y ago
If you want to package it in, that would mean building a custom Deno which is not impossible but is a bit complicated. If you rather want to just expose the Rust API through FFI, then https://github.com/denoland/deno_bindgen can help you with that.
GitHub
GitHub - denoland/deno_bindgen: Simplified glue code generation for...
Simplified glue code generation for Deno FFI libraries written in Rust. - GitHub - denoland/deno_bindgen: Simplified glue code generation for Deno FFI libraries written in Rust.

Did you find this page helpful?