-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun.rs
47 lines (40 loc) · 1.14 KB
/
run.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use restate_sdk::prelude::*;
use std::collections::HashMap;
#[restate_sdk::service]
trait RunExample {
async fn do_run() -> Result<Json<HashMap<String, String>>, HandlerError>;
}
struct RunExampleImpl(reqwest::Client);
impl RunExample for RunExampleImpl {
async fn do_run(
&self,
context: Context<'_>,
) -> Result<Json<HashMap<String, String>>, HandlerError> {
let res = context
.run(|| async move {
let req = self.0.get("https://httpbin.org/ip").build()?;
let res = self
.0
.execute(req)
.await?
.json::<HashMap<String, String>>()
.await?;
Ok(Json::from(res))
})
.name("get_ip")
.await?
.into_inner();
Ok(res.into())
}
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
HttpServer::new(
Endpoint::builder()
.bind(RunExampleImpl(reqwest::Client::new()).serve())
.build(),
)
.listen_and_serve("0.0.0.0:9080".parse().unwrap())
.await;
}