Skip to content

Commit

Permalink
33: method - status
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Jan 16, 2024
1 parent 77a1a11 commit 4077cec
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xps-gateway/src/rpc/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ pub trait Xps {
// Placeholder for send_message, see [the discussion](https://github.com/xmtp/xps-gateway/discussions/11)
#[method(name = "sendMessage")]
async fn send_message(&self, _message: Message) -> Result<(), ErrorObjectOwned>;

#[method(name = "status")]
async fn status(&self) -> Result<String, ErrorObjectOwned>;
}
91 changes: 91 additions & 0 deletions xps-gateway/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,95 @@ impl XpsServer for XpsMethods {
log::debug!("xps_sendMessage called");
todo!();
}

/// # Documentation for JSON RPC Endpoint: `status`
/// ## Overview
/// The `status` method is used to query the gateway status.
/// ## JSON RPC Endpoint Specification
/// ### Method Name
/// `status`
/// ### Request Parameters
/// none
/// ### Request Format
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "method": "status",
/// "id": 1
/// }
/// ```
/// - `jsonrpc`: Specifies the version of the JSON RPC protocol being used. Always "2.0".
/// - `method`: The name of the method being called. Here it is "status".
/// - `id`: A unique identifier established by the client that must be number or string. Used for correlating the response with the request.
/// ### Response Format
/// The response will typically include the result of the operation or an error if the operation was unsuccessful.
/// #### Success Response
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "result": "OK",
/// "id": 1
/// }
/// ```
/// - `result`: Contains data related to the success of the operation. The nature of this data can vary based on the implementation.
/// #### Error Response
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "error": {
/// "code": <error_code>,
/// "message": "<error_message>"
/// },
/// "id": 1
/// }
/// ```
/// - `error`: An object containing details about the error.
/// - `code`: A numeric error code.
/// - `message`: A human-readable string describing the error.
/// ### Example Usage
/// #### Request
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "method": "status",
/// "id": 42
/// }
/// ```
/// #### Response
/// ```json
/// {
/// "jsonrpc": "2.0",
/// "result": "OK",
/// "id": 42
/// }
/// ```
/// ### Command Line Example
/// ```bash
/// $ $ curl -H "Content-Type: application/json" -d '{"id":7000, "jsonrpc":"2.0", "method":"xps_status"}' http:///localhost:34695
/// {"jsonrpc":"2.0","result":"OK","id":7000}
/// ```
/// ### Notes
/// - The system should have proper error handling to deal with invalid requests, unauthorized access, and other potential issues.
async fn status(&self) -> Result<String, ErrorObjectOwned> {
log::debug!("xps_status called");
Ok("OK".to_string())
}
}

0 comments on commit 4077cec

Please sign in to comment.