dapr / dapr/rust-sdk

How to invoke a HTTP service

Open Beginner friendly
#243 1 comment 0 reactions 0 assignees View on GitHub
documentation good first issue P2
Dominant language
Rust
Stars
252
Forks
73
PR merge metrics
No merged PRs in 30d

Description

## Describe the feature/proposal

Include a section to invoke a HTTP service.

### Sample code

#### Cargo.toml

```rust
reqwest = "0.12.9"
dapr = "0.15.1"
tokio = "1.41.1"
```

After several optimizations, my `Cargo.toml` file is this way and it is running:

```rust
reqwest = { version = "0.12.9", default-features = false }
dapr = "0.15.1"
tokio = "1.41.1"
```

#### Rust code

This example uses:
- query parameter
- header value

```rust
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
let client_result = dapr::Client::::connect(format!("{}", ADDR)).await;
let method_to_call = format!("/{}", value);
match client_result {
Ok(mut client) => {
// Create a new HTTP client
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(2)) // the value what you need
.build()
.unwrap();

// Post the method
// ADDR = "127.0.0.1"
// PORT =
let url = format!("{}:{}/{}", ADDR, PORT, method_to_call);
let req = client.post(url).header("dapr-app-id", "");

let response_result = req.send().await;
match response_result {
Ok(response) => {
let body_result = response.text().await;
match body_result {
Ok(body) => {
println!("Response: {:?}", body);
},
Err(e) => {
eprintln!("e1: {}", e);
}
}
},
Err(e) => {
eprintln!("e2: {}", e);
}
}
},
Err(e) => {
eprintln!("Dapr client error: {}", e);
}
}
});
```

## Release Note
RELEASE NOTE: **ADD** New example to invoke to a HTTP service in the Rust SDK.

Contributor guide

Open the contributing guide

Research direction

Use the Cargo.toml dependency snippet and Rust code as source material; first locate the Rust SDK's existing documentation or example section where HTTP service invocation belongs. Add the example covering query parameters and a header value, then confirm the documentation presents the requested Rust usage clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.