Remove remaining references to hyper and use new header style in docs.

This commit is contained in:
Jimmy Cuadra 2018-05-15 01:49:42 -07:00
parent 7b1e22eea4
commit a035c233be
2 changed files with 38 additions and 29 deletions

View File

@ -13,7 +13,7 @@ Here is an example that shows most of the macro's functionality.
#![feature(associated_consts, proc_macro, try_from)] #![feature(associated_consts, proc_macro, try_from)]
extern crate futures; extern crate futures;
extern crate hyper; extern crate http;
extern crate ruma_api; extern crate ruma_api;
extern crate ruma_api_macros; extern crate ruma_api_macros;
extern crate serde; extern crate serde;
@ -28,9 +28,9 @@ pub mod some_endpoint {
ruma_api! { ruma_api! {
metadata { metadata {
description: "Does something.", description: "Does something.",
method: Method::Get, // A `hyper::Method` value. No need to import the name. method: GET, // An `http::Method` constant. No imports required.
name: "some_endpoint", name: "some_endpoint",
path: "/_matrix/some/endpoint/:baz", path: "/_matrix/some/endpoint/:baz", // Variable path components start with a colon.
rate_limited: false, rate_limited: false,
requires_authentication: false, requires_authentication: false,
} }
@ -40,8 +40,8 @@ pub mod some_endpoint {
pub foo: String, pub foo: String,
// This value will be put into the "Content-Type" HTTP header. // This value will be put into the "Content-Type" HTTP header.
#[ruma_api(header)] #[ruma_api(header = "CONTENT_TYPE")]
pub content_type: ContentType, pub content_type: String
// This value will be put into the query string of the request's URL. // This value will be put into the query string of the request's URL.
#[ruma_api(query)] #[ruma_api(query)]
@ -55,8 +55,8 @@ pub mod some_endpoint {
response { response {
// This value will be extracted from the "Content-Type" HTTP header. // This value will be extracted from the "Content-Type" HTTP header.
#[ruma_api(header)] #[ruma_api(header = "CONTENT_TYPE")]
pub content_type: ContentType, pub content_type: String
// With no attribute on the field, it will be extracted from the body of the response. // With no attribute on the field, it will be extracted from the body of the response.
pub value: String, pub value: String,

View File

@ -28,7 +28,7 @@ mod api;
/// ruma_api! { /// ruma_api! {
/// metadata { /// metadata {
/// description: &'static str /// description: &'static str
/// method: hyper::Method, /// method: http::Method,
/// name: &'static str, /// name: &'static str,
/// path: &'static str, /// path: &'static str,
/// rate_limited: bool, /// rate_limited: bool,
@ -50,8 +50,8 @@ mod api;
/// ///
/// This will generate a `ruma_api::Metadata` value to be used for the `ruma_api::Endpoint`'s /// This will generate a `ruma_api::Metadata` value to be used for the `ruma_api::Endpoint`'s
/// associated constant, single `Request` and `Response` structs, and the necessary trait /// associated constant, single `Request` and `Response` structs, and the necessary trait
/// implementations to convert the request into a `hyper::Request` and to create a response from a /// implementations to convert the request into a `http::Request` and to create a response from a
/// `hyper::response`. /// `http::Response`.
/// ///
/// The details of each of the three sections of the macros are documented below. /// The details of each of the three sections of the macros are documented below.
/// ///
@ -59,8 +59,8 @@ mod api;
/// ///
/// * `description`: A short description of what the endpoint does. /// * `description`: A short description of what the endpoint does.
/// * `method`: The HTTP method used for requests to the endpoint. /// * `method`: The HTTP method used for requests to the endpoint.
/// It's not necessary to import `hyper::Method`, you just write the value as if it was /// It's not necessary to import `http::Method`'s associated constants. Just write
/// imported, e.g. `Method::Get`. /// the value as if it was imported, e.g. `GET`.
/// * `name`: A unique name for the endpoint. /// * `name`: A unique name for the endpoint.
/// Generally this will be the same as the containing module. /// Generally this will be the same as the containing module.
/// * `path`: The path component of the URL for the endpoint, e.g. "/foo/bar". /// * `path`: The path component of the URL for the endpoint, e.g. "/foo/bar".
@ -76,11 +76,14 @@ mod api;
/// The request block contains normal struct field definitions. /// The request block contains normal struct field definitions.
/// Doc comments and attributes are allowed as normal. /// Doc comments and attributes are allowed as normal.
/// There are also a few special attributes available to control how the struct is converted into a /// There are also a few special attributes available to control how the struct is converted into a
/// `hyper::Request`: /// `http::Request`:
/// ///
/// * `#[ruma_api(header)]`: Fields with this attribute will be treated as HTTP headers on the /// * `#[ruma_api(header = "HEADER_NAME")]`: Fields with this attribute will be treated as HTTP
/// request. /// headers on the request.
/// The value must implement `hyper::header::Header`. /// The value must implement `http::HttpTryFrom for http::header::HeaderValue`.
/// Generally this is a string.
/// The attribute value shown above as `HEADER_NAME` must be a header name constant from
/// `http::header`, e.g. `CONTENT_TYPE`.
/// * `#[ruma_api(path)]`: Fields with this attribute will be inserted into the matching path /// * `#[ruma_api(path)]`: Fields with this attribute will be inserted into the matching path
/// component of the request URL. /// component of the request URL.
/// * `#[ruma_api(query)]`: Fields with this attribute will be inserting into the URL's query /// * `#[ruma_api(query)]`: Fields with this attribute will be inserting into the URL's query
@ -94,11 +97,14 @@ mod api;
/// Like the request block, the response block consists of normal struct field definitions. /// Like the request block, the response block consists of normal struct field definitions.
/// Doc comments and attributes are allowed as normal. /// Doc comments and attributes are allowed as normal.
/// There is also a special attribute available to control how the struct is created from a /// There is also a special attribute available to control how the struct is created from a
/// `hyper::Request`: /// `http::Request`:
/// ///
/// * `#[ruma_api(header)]`: Fields with this attribute will be treated as HTTP headers on the /// * `#[ruma_api(header = "HEADER_NAME")]`: Fields with this attribute will be treated as HTTP
/// response. /// headers on the response.
/// The value must implement `hyper::header::Header`. /// The value must implement `http::HttpTryFrom for http::header::HeaderValue`.
/// Generally this is a string.
/// The attribute value shown above as `HEADER_NAME` must be a header name constant from
/// `http::header`, e.g. `CONTENT_TYPE`.
/// ///
/// Any field that does not include the above attribute will be expected in the response's JSON /// Any field that does not include the above attribute will be expected in the response's JSON
/// body. /// body.
@ -115,10 +121,10 @@ mod api;
/// # Examples /// # Examples
/// ///
/// ```rust,no_run /// ```rust,no_run
/// #![feature(associated_consts, proc_macro, try_from)] /// #![feature(proc_macro, try_from)]
/// ///
/// extern crate futures; /// extern crate futures;
/// extern crate hyper; /// extern crate http;
/// extern crate ruma_api; /// extern crate ruma_api;
/// extern crate ruma_api_macros; /// extern crate ruma_api_macros;
/// extern crate serde; /// extern crate serde;
@ -129,13 +135,12 @@ mod api;
/// ///
/// # fn main() { /// # fn main() {
/// pub mod some_endpoint { /// pub mod some_endpoint {
/// use hyper::header::ContentType;
/// use ruma_api_macros::ruma_api; /// use ruma_api_macros::ruma_api;
/// ///
/// ruma_api! { /// ruma_api! {
/// metadata { /// metadata {
/// description: "Does something.", /// description: "Does something.",
/// method: Method::Get, /// method: GET,
/// name: "some_endpoint", /// name: "some_endpoint",
/// path: "/_matrix/some/endpoint/:baz", /// path: "/_matrix/some/endpoint/:baz",
/// rate_limited: false, /// rate_limited: false,
@ -144,17 +149,21 @@ mod api;
/// ///
/// request { /// request {
/// pub foo: String, /// pub foo: String,
/// #[ruma_api(header)] ///
/// pub content_type: ContentType, /// #[ruma_api(header = "CONTENT_TYPE")]
/// pub content_type: String,
///
/// #[ruma_api(query)] /// #[ruma_api(query)]
/// pub bar: String, /// pub bar: String,
///
/// #[ruma_api(path)] /// #[ruma_api(path)]
/// pub baz: String, /// pub baz: String,
/// } /// }
/// ///
/// response { /// response {
/// #[ruma_api(header)] /// #[ruma_api(header = "CONTENT_TYPE")]
/// pub content_type: ContentType, /// pub content_type: String,
///
/// pub value: String, /// pub value: String,
/// } /// }
/// } /// }
@ -171,7 +180,7 @@ mod api;
/// ruma_api! { /// ruma_api! {
/// metadata { /// metadata {
/// description: "Does something.", /// description: "Does something.",
/// method: Method::Get, /// method: GET,
/// name: "newtype_body_endpoint", /// name: "newtype_body_endpoint",
/// path: "/_matrix/some/newtype/body/endpoint", /// path: "/_matrix/some/newtype/body/endpoint",
/// rate_limited: false, /// rate_limited: false,