Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
debug
target
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand All @@ -19,3 +20,8 @@ target
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# Added by cargo

/target
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2025-11-03

### Added
- Initial release of ServiceStack Rust HTTP Client Library
- Core `ServiceStackClient` for making HTTP requests
- Support for all HTTP methods: GET, POST, PUT, DELETE, PATCH
- Async/await support with tokio
- JSON serialization/deserialization with serde
- Type-safe request/response handling
- Comprehensive documentation and examples
- Error handling with custom error types
- Basic usage example demonstrating client functionality

[0.1.0]: https://github.com/ServiceStack/servicestack-rust/releases/tag/v0.1.0
23 changes: 23 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "servicestack"
version = "0.1.0"
edition = "2021"
authors = ["ServiceStack, Inc."]
license = "BSD-3-Clause"
description = "ServiceStack HTTP Client Library for Rust"
documentation = "https://docs.rs/servicestack"
repository = "https://github.com/ServiceStack/servicestack-rust"
homepage = "https://servicestack.net"
readme = "README.md"
keywords = ["servicestack", "http", "client", "api", "rest"]
categories = ["web-programming::http-client", "api-bindings"]

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
thiserror = "1.0"

[dev-dependencies]
tokio-test = "0.4"
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2025, ServiceStack, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102 changes: 102 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Publishing to crates.io

This document describes how to publish the ServiceStack Rust client library to crates.io.

## Prerequisites

1. Create an account on [crates.io](https://crates.io/)
2. Get your API token from [crates.io/me](https://crates.io/me)
3. Configure your token locally:
```bash
cargo login <your-api-token>
```

## Pre-publication Checklist

Before publishing, ensure:

- [ ] All tests pass: `cargo test`
- [ ] Documentation builds without warnings: `cargo doc --no-deps`
- [ ] Package builds successfully: `cargo package`
- [ ] Version number is correct in `Cargo.toml`
- [ ] `CHANGELOG.md` is updated
- [ ] `README.md` is accurate and up-to-date
- [ ] License file exists and is correct
- [ ] All code is committed and pushed to GitHub

## Package Verification

1. Build and test the package:
```bash
cargo build
cargo test
```

2. Verify the package contents:
```bash
cargo package --list
```

3. Build the package to check for issues:
```bash
cargo package
```

4. Test the packaged version:
```bash
cargo package
cd target/package
cargo test
```

## Publishing

Once all checks pass, publish to crates.io:

```bash
cargo publish
```

This will:
1. Package your crate
2. Upload it to crates.io
3. Make it available for download via `cargo install`

## Post-Publication

After publishing:

1. Create a GitHub release:
- Tag: `v0.1.0`
- Title: `ServiceStack Rust v0.1.0`
- Description: Copy from CHANGELOG.md

2. Verify the package appears on crates.io:
- Visit https://crates.io/crates/servicestack
- Check that documentation is generated at https://docs.rs/servicestack

3. Test installation:
```bash
cargo new test-project
cd test-project
cargo add servicestack
cargo build
```

## Version Updates

For future releases:

1. Update version in `Cargo.toml`
2. Update `CHANGELOG.md` with new changes
3. Commit and push changes
4. Run through the pre-publication checklist
5. Publish with `cargo publish`
6. Create a new GitHub release

## Troubleshooting

- **Publishing fails**: Check that all required fields in `Cargo.toml` are filled
- **Documentation fails to build**: Run `cargo doc` locally to see errors
- **Tests fail**: Run `cargo test` to identify and fix failing tests
- **Version conflict**: Ensure version number is incremented from last published version
140 changes: 138 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,138 @@
# servicestack-rust
ServiceStack Client Rust Library
# ServiceStack Rust Client Library

A Rust client library for ServiceStack services, providing type-safe HTTP communication with async/await support.

[![Crates.io](https://img.shields.io/crates/v/servicestack.svg)](https://crates.io/crates/servicestack)
[![Documentation](https://docs.rs/servicestack/badge.svg)](https://docs.rs/servicestack)
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](LICENSE)

## Features

- 🚀 **Async/await support** - Built on tokio for efficient async operations
- 📦 **Type-safe** - Leverages Rust's type system with serde for serialization
- 🔧 **Flexible** - Support for all HTTP methods (GET, POST, PUT, DELETE, PATCH)
- 🛡️ **Reliable** - Built on reqwest for robust HTTP communication
- 📖 **Well-documented** - Comprehensive API documentation and examples

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
servicestack = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
```

## Quick Start

```rust
use servicestack::{ServiceStackClient, Result};
use serde::{Deserialize, Serialize};

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

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

#[tokio::main]
async fn main() -> Result<()> {
// Create a new client
let client = ServiceStackClient::new("https://example.org");

// Make a POST request
let request = HelloRequest {
name: "World".to_string()
};
let response: HelloResponse = client.post("/hello", &request).await?;

println!("{}", response.result);
Ok(())
}
```

## Usage Examples

### GET Request

```rust
use servicestack::{ServiceStackClient, Result};
use serde::Deserialize;

#[derive(Deserialize)]
struct User {
id: u64,
name: String,
}

async fn get_user(client: &ServiceStackClient, id: u64) -> Result<User> {
client.get(&format!("/users/{}", id)).await
}
```

### POST Request

```rust
use servicestack::{ServiceStackClient, Result};
use serde::{Deserialize, Serialize};

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

#[derive(Deserialize)]
struct CreateUserResponse {
id: u64,
name: String,
}

async fn create_user(client: &ServiceStackClient) -> Result<CreateUserResponse> {
let request = CreateUserRequest {
name: "John Doe".to_string(),
email: "john@example.com".to_string(),
};
client.post("/users", &request).await
}
```

### Custom Client Configuration

```rust
use servicestack::ServiceStackClient;
use reqwest::Client;
use std::time::Duration;

let custom_client = Client::builder()
.timeout(Duration::from_secs(60))
.build()
.unwrap();

let client = ServiceStackClient::with_client(
"https://api.example.com",
custom_client
);
```

## API Documentation

For detailed API documentation, visit [docs.rs/servicestack](https://docs.rs/servicestack).

## License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## About ServiceStack

[ServiceStack](https://servicestack.net) is a simple, fast, versatile and highly-productive full-featured Web and Web Services Framework.
44 changes: 44 additions & 0 deletions examples/basic_usage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Basic usage example for the ServiceStack client library
//!
//! This example demonstrates how to use the ServiceStack client
//! to make HTTP requests to a ServiceStack service.

use servicestack::{ServiceStackClient, Result};
use serde::{Deserialize, Serialize};

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

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

#[tokio::main]
async fn main() -> Result<()> {
// Create a new ServiceStack client
let client = ServiceStackClient::new("https://test.servicestack.net");

// Example 1: Simple GET request
println!("Example 1: GET request");
match client.get::<serde_json::Value>("/hello/World").await {
Ok(response) => println!("Response: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}

// Example 2: POST request with JSON body
println!("\nExample 2: POST request");
let request = HelloRequest {
name: "Rust".to_string(),
};

match client.post::<_, HelloResponse>("/hello", &request).await {
Ok(response) => println!("Response: {:?}", response),
Err(e) => eprintln!("Error: {}", e),
}

println!("\nExamples completed!");
Ok(())
}
Loading