Canapi
Common Canapi traits.
Canapi is a collection of Rust crate to make it possible to share a REST API definition between
clients and servers. You define your endpoints (Endpoint
trait), bind them to your databse (Provider
trait),
and you can re-use these endpoints in your client (Fetch
trait).
This requires three separate crates: one for your API defintion, one for your server, and one for the client.
Example
my-api
, where you define the API.
use Endpoint;
my-server
, to bind endpoints to database (and expose them to the rest of the world)
use Provider;
use *; // Example with Diesel
use UserEndpoint;
/// Define the User model…
// Use rocket, actix-web, iron, gotham or whatever you want to expose your endpoints…
my-client
, to use your API (here with a potential WASM Fetch
impl)
use WasmFetch;
use plume_api;