Remix.run Logo
tormeh 13 hours ago

Often each API route will have its own handler function. That function will - usually through many layers of indirection and abstraction - launch queries towards your database.

littlecranky67 12 hours ago | parent [-]

That describe a REST API implementation design, but doesn't really answer the particular question: How is the scoping implemented, i.e. how would any given Rust REST API framework couple a Db transaction to a HTTP scope. I mean, I know how that would look like if the framework ofered you no abstraction or DI whatsoever. You would pass the transaction (and maybe database handle) through all sorts of functions, create some sort of context object (that holds all sort of references to the http connection, database, transaction and whatnot, and call everything manually. Eventually you will end up building a similar custom-made abstraction that the built-in DI container in ASP.NET does. But I would expect there are some frameworks for rust that already deliver that.

tormeh 10 hours ago | parent [-]

Axum is the most popular web library out there, and sqlx the most popular sql library. Together they look something like this: https://github.com/tokio-rs/axum/blob/main/examples%2Fsqlx-p...