Skip to main content

psibase/
web_services.rs

1/// Interface for services which serve http
2///
3/// The `http-server` service uses this interface to call into other services to respond
4/// to http requests.
5///
6/// To implement this interface, add a [serveSys](ServerActions::serveSys) action to
7/// your service.
8#[crate::service(
9    name = "example-server",
10    actions = "ServerActions",
11    wrapper = "ServerWrapper",
12    structs = "server_action_structs",
13    dispatch = false,
14    pub_constant = false,
15    psibase_mod = "crate"
16)]
17#[allow(non_snake_case, unused_variables)]
18pub mod server_interface {
19    use crate::*;
20
21    /// Handle HTTP requests
22    ///
23    /// Define this action in your service to handle HTTP requests. You'll also need to
24    /// register your service by calling the registerServer action in the `http-server`
25    /// service.
26    ///
27    /// `serveSys` can do any of the following:
28    ///
29    /// - Return `None` to signal not found. psinode produces a 404 response in this case.
30    /// - Abort. psinode produces a 500 response with the service's abort message.
31    /// - Return a [psibase::HttpReply](crate::HttpReply). psinode produces a 200 response with the body and contentType returned.
32    /// - Call other services.
33    /// - Call `http-server::sendReply`. Explicitly sends a response.
34    /// - Call `http-server::deferReply`. No response will be produced until `http-server::sendReply` is called.
35    ///
36    /// A service runs in RPC mode while serving an HTTP request. This mode prevents database writes,
37    /// but allows database reads, including reading data and events which are normally not available
38    /// to services; see [psibase::DbId](crate::DbId).
39    #[action]
40    fn serveSys(
41        request: HttpRequest,
42        socket: Option<i32>,
43        user: Option<AccountNumber>,
44    ) -> Option<HttpReply> {
45        unimplemented!()
46    }
47}