Expand description
A lightweight framework to define APIs as types.
The core functionality of this crate is to define APIs as types bound by traits. Based on these definitions it is possible to reason about an API from different perspectives: derive, type check and much more.
-
A method is defined as
Request→ (method name,Response) dependency in the context of an API (SeeHasMethod). -
An API is defined as
ApiMetaType→[*]dependency (SeeIsApi), where[*]is a heterogeneous list of request types that belong to the API.
You can define these traits manually, but you should use define_api
macro instead.
The extra functionality of this crate is to provide some tools to build implementors of APIs and some basic middleware/combinators for those implementors.
- An implementor is a type that implements an API via
ImplsMethod. TheImplsMethodtrait is somewhat similar totower::Serviceand other similar traits.
It is possible to use only the core functionality of this crate in
combination with any “service trait”. But since tower is quite old and
low-level and there’s no established industry standard alternatives, this
crate uses ImplsMethod to define that extra functionality.
Modules§
- client
client - Utilities for calling an API as a client.
- combinator
- A few built-in API and implementor combinators.
- generate
- Utilities to generate specifications, IDLs, SDKs, etc.
- server
- Utilities for exposing an API implementor as a server.
Macros§
- define_
api - Main macro to define APIs in
aisilformat.
Structs§
- Boxed
Impl - Wrapper for implementors of
ImplsMethodBoxed
Traits§
- CallApi
- Helper trait to allow pretty type applications that
ImplsMethoddoes not allow. You may need it when one request belongs to two APIs and a backend implements both of them. You should not reuse requests in different APIs but in case you do, this would be helpful. - HasMethod
- Type dependency from
Request→Responsein the context of an API - Impls
Method - Generalization over an asyncronous function bound by an API definition.
Similar to
tower::Servicebut associated types are defined in the API definition instead of the trait itself. - Impls
Method Boxed - Same as
ImplsMethodbut dyn-compatible - IsApi
- API definition as a type. Use
define_apimacro to define this impl.