Extract Method and Endpoint to the ruma-api crate.

This commit is contained in:
Jimmy Cuadra 2016-12-15 02:00:00 -08:00
parent c48ba8cb51
commit eb784ab49b
2 changed files with 3 additions and 39 deletions

View File

@ -11,6 +11,7 @@ repository = "https://github.com/ruma/ruma-client-api"
version = "0.1.0"
[dependencies]
ruma-api = "0.1.0"
ruma-events = "0.1.0"
ruma-identifiers = "0.5.0"
ruma-signatures = "0.1.0"

View File

@ -4,6 +4,7 @@
#![feature(proc_macro)]
extern crate ruma_api;
extern crate ruma_events;
extern crate ruma_identifiers;
extern crate ruma_signatures;
@ -11,7 +12,7 @@ extern crate serde;
#[macro_use] extern crate serde_derive;
extern crate serde_json;
use serde::{Deserialize, Serialize};
pub use ruma_api::{Endpoint, Method};
/// Endpoints for the r0.x.x versions of the client API specification.
pub mod r0 {
@ -42,41 +43,3 @@ pub mod r0 {
/// GET /_matrix/client/versions
pub mod supported_versions;
/// HTTP request methods used in Matrix APIs.
#[derive(Clone, Copy, Debug)]
pub enum Method {
/// DELETE
Delete,
/// GET
Get,
/// POST
Post,
/// PUT
Put,
}
/// An API endpoint.
pub trait Endpoint {
/// Request parameters supplied via the body of the HTTP request.
type BodyParams: Deserialize + Serialize;
/// Request parameters supplied via the URL's path.
type PathParams;
/// Parameters supplied via the URL's query string.
type QueryParams;
/// The body of the response.
type Response: Deserialize + Serialize;
/// Returns the HTTP method used by this endpoint.
fn method() -> Method;
/// Generates the path component of the URL for this endpoint using the supplied parameters.
fn request_path(params: Self::PathParams) -> String;
/// Generates a generic path component of the URL for this endpoint, suitable for `Router` from
/// the router crate.
fn router_path() -> String;
}