#matrix #chat #messaging #ruma

macro ruma-api-macros

A procedural macro for generating ruma-api Endpoints

27 releases (14 breaking)

0.17.0-alpha.1 Jul 29, 2020
0.16.0-rc.3 Apr 22, 2020
0.12.0 Mar 29, 2020
0.9.0 Dec 12, 2019
0.1.0 Jul 7, 2017

#150 in Web programming

Download history 409/week @ 2020-05-28 406/week @ 2020-06-04 244/week @ 2020-06-11 218/week @ 2020-06-18 128/week @ 2020-06-25 310/week @ 2020-07-02 164/week @ 2020-07-09 177/week @ 2020-07-16 45/week @ 2020-07-23 50/week @ 2020-07-30 82/week @ 2020-08-06 68/week @ 2020-08-13 79/week @ 2020-08-20 118/week @ 2020-08-27 151/week @ 2020-09-03 34/week @ 2020-09-10

1,369 downloads per month
Used in 15 crates (via ruma-api)

MIT license

67KB
1.5K SLoC

ruma-api-macros

ruma-api-macros provides a procedural macro for easily generating ruma-api-compatible API endpoints. You define the endpoint's metadata, request fields, and response fields, and the macro generates all the necessary types and implements all the necessary traits.

Usage

This crate is not meant to be used directly; instead, you can use it through the re-exports in ruma-api.

Here is an example that shows most of the macro's functionality:

pub mod some_endpoint {
    use ruma_api::ruma_api;

    ruma_api! {
        metadata: {
            description: "Does something.",
            method: GET, // An `http::Method` constant. No imports required.
            name: "some_endpoint",
            path: "/_matrix/some/endpoint/:baz", // Variable path components start with a colon.
            rate_limited: false,
            requires_authentication: false,
        }

        request: {
            // With no attribute on the field, it will be put into the body of the request.
            pub foo: String,

            // This value will be put into the "Content-Type" HTTP header.
            #[ruma_api(header = CONTENT_TYPE)]
            pub content_type: String

            // This value will be put into the query string of the request's URL.
            #[ruma_api(query)]
            pub bar: String,

            // This value will be inserted into the request's URL in place of the
            // ":baz" path component.
            #[ruma_api(path)]
            pub baz: String,
        }

        response: {
            // This value will be extracted from the "Content-Type" HTTP header.
            #[ruma_api(header = CONTENT_TYPE)]
            pub content_type: String

            // With no attribute on the field, it will be extracted from the body of the response.
            pub value: String,
        }

        // An error can also be specified or defaults to `ruma_api::error::Void`.
        error: ruma_api::Error
    }
}

Documentation

Please refer to the documentation of the ruma_api! re-export in ruma-api.

License

MIT

Dependencies

~0.4–0.8MB
~21K SLoC