ruma_client_api/account/get_username_availability.rs
1//! `GET /_matrix/client/*/register/available`
2//!
3//! Checks to see if a username is available, and valid, for the server.
4
5pub mod v3 {
6 //! `/v3/` ([spec])
7 //!
8 //! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3registeravailable
9
10 use ruma_common::{
11 api::{request, response, Metadata},
12 metadata,
13 };
14
15 const METADATA: Metadata = metadata! {
16 method: GET,
17 rate_limited: true,
18 authentication: None,
19 history: {
20 1.0 => "/_matrix/client/r0/register/available",
21 1.1 => "/_matrix/client/v3/register/available",
22 }
23 };
24
25 /// Request type for the `get_username_availability` endpoint.
26 #[request(error = crate::Error)]
27 pub struct Request {
28 /// The username to check the availability of.
29 #[ruma_api(query)]
30 pub username: String,
31 }
32
33 /// Response type for the `get_username_availability` endpoint.
34 #[response(error = crate::Error)]
35 pub struct Response {
36 /// A flag to indicate that the username is available.
37 /// This should always be true when the server replies with 200 OK.
38 pub available: bool,
39 }
40
41 impl Request {
42 /// Creates a new `Request` with the given username.
43 pub fn new(username: String) -> Self {
44 Self { username }
45 }
46 }
47
48 impl Response {
49 /// Creates a new `Response` with the given availability flag.
50 pub fn new(available: bool) -> Self {
51 Self { available }
52 }
53 }
54}