Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Implements a JsonServiceClient for Rust that enables type-safe API requests to ServiceStack services using Add ServiceStack Reference DTOs.

Core Implementation

  • JsonServiceClient - HTTP client with methods for GET, POST, PUT, DELETE, PATCH
  • ServiceStackRequest/Response traits - Type system for request/response DTOs with path routing
  • HttpMethod enum - Custom method support per request type
  • Bearer token authentication - set_bearer_token() / clear_bearer_token()
  • ServiceStackError - Typed errors for HTTP, JSON, and API failures

Usage

use servicestack::{JsonServiceClient, ServiceStackRequest, ServiceStackResponse};
use serde::{Deserialize, Serialize};

#[derive(Serialize)]
struct Hello {
    name: String,
}

impl ServiceStackRequest for Hello {
    type Response = HelloResponse;
    fn path(&self) -> String { "/hello".to_string() }
}

#[derive(Deserialize)]
struct HelloResponse {
    result: String,
}

impl ServiceStackResponse for HelloResponse {}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = JsonServiceClient::new("https://api.example.com");
    let response: HelloResponse = client.post(Hello { 
        name: "World".to_string() 
    }).await?;
    Ok(())
}

Testing

  • Unit tests for client configuration and URL handling
  • Integration tests with mockito for HTTP scenarios (auth, errors, methods)
  • 4 examples demonstrating authentication, custom methods, and basic usage

Dependencies

Built on reqwest (HTTP), serde (JSON), tokio (async), thiserror (errors).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • test.servicestack.net
    • Triggering command: target/debug/examples/complete_example (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Creating a ServiceStack JsonServiceClient for the Rust programming language that uses the Rust Add ServiceStack Language DTOs to make API Requests


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 3, 2025 18:14
Co-authored-by: mythz <89361+mythz@users.noreply.github.com>
Co-authored-by: mythz <89361+mythz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ServiceStack JsonServiceClient for Rust programming language Add ServiceStack JsonServiceClient for Rust with typed DTOs Nov 3, 2025
Copilot AI requested a review from mythz November 3, 2025 18:22
Copilot finished work on behalf of mythz November 3, 2025 18:22
@mythz mythz marked this pull request as ready for review November 4, 2025 08:34
Copy link
Member

@mythz mythz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mythz mythz merged commit b5a2bfa into main Nov 4, 2025
0 of 4 checks passed
@mythz mythz deleted the copilot/add-jsonserviceclient-for-rust branch November 4, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants