roadster-rs / roadster

"Batteries Included" web framework for Rust designed to get you moving fast 🏎️
Apache License 2.0
3 stars 0 forks source link

How to call api from rust frontend #236

Open spencewenski opened 1 week ago

spencewenski commented 1 week ago

If the consumer is using a rust ui framework, eg leptos, we should make it easy to call the api. Do we require building an OpenApi client in this case? Seems a little weird tbh. Maybe we can generate leptos server fn wrappers? How to do that without creating duplicate api routes?

spencewenski commented 1 week ago

And/or, can leptos be updated to generate an OpenApi schema?

spencewenski commented 1 week ago

TBD, how to support other frameworks besides leptos? Just with an openapi client?

spencewenski commented 1 week ago

First, the benefits of having open api support vs leptos’s server functions?

open api pros:

  1. easy to integrate with postman/bruno and other e2e api testing tools
  2. Easily allow external parties to integrate
  3. Easily support multiple platforms/languages for the FE
  4. Can deploy/scale the api separately from the ui

open api cons:

  1. More complicated setup/build process
  2. More boilerplate to define routes
  3. More complicated to call the APIs vs leptos server functions
  4. Unnecessarily duplicating types
spencewenski commented 1 week ago

I wonder how hard it would be to generate an open api schema for leptos server functions? I think one issue is server functions would possibly tend to be pretty specific and not really well designed APIs. It could be helpful for development, though.