Crate ruma_api [−] [src]
Crate ruma_api contains core types used to define the requests and responses for each endpoint in the various Matrix API specifications. These types can be shared by client and server code for all Matrix APIs.
When implementing a new Matrix API, each endpoint have a type that implements Endpoint
, plus
any necessary associated types.
An implementation of Endpoint
contains all the information about the HTTP method, the path and
input parameters for requests, and the structure of a successful response.
Such types can then be used by client code to make requests, and by server code to fulfill
those requests.
Example
/// PUT /_matrix/client/r0/directory/room/:room_alias pub mod create { use ruma_api; use ruma_identifiers::{RoomAliasId, RoomId}; /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub room_id: RoomId, } /// This API endpoint's path parameters. pub struct PathParams { pub room_alias: RoomAliasId, } /// Details about this API endpoint. pub struct Endpoint; impl ruma_api::Endpoint for Endpoint { type BodyParams = BodyParams; type PathParams = PathParams; type QueryParams = (); type Response = (); fn method() -> ruma_api::Method { ruma_api::Method::Put } fn request_path(params: Self::PathParams) -> String { format!("/_matrix/client/r0/directory/room/{}", params.room_alias) } fn router_path() -> String { "/_matrix/client/r0/directory/room/:room_alias".to_string() } } }
Enums
Method |
HTTP request methods used in Matrix APIs. |
Traits
Endpoint |
An API endpoint. |