{"id":21327873,"url":"https://github.com/siddiqsoft/restcl","last_synced_at":"2026-05-01T07:01:27.068Z","repository":{"id":47000183,"uuid":"391225960","full_name":"SiddiqSoft/restcl","owner":"SiddiqSoft","description":"Focused REST client for modern C++","archived":false,"fork":false,"pushed_at":"2025-02-01T06:02:28.000Z","size":688,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-14T23:42:03.142Z","etag":null,"topics":["async","cpp20","json-api","nlohmann-json","nuget","rest-client","windows","winhttp"],"latest_commit_sha":null,"homepage":"https://siddiqsoft.github.io/restcl/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SiddiqSoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-31T01:22:07.000Z","updated_at":"2024-12-17T01:04:11.000Z","dependencies_parsed_at":"2024-12-16T22:47:28.749Z","dependency_job_id":"f9e2d5bc-3773-4851-8159-4a13c76dfd1b","html_url":"https://github.com/SiddiqSoft/restcl","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Frestcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Frestcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Frestcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiddiqSoft%2Frestcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SiddiqSoft","download_url":"https://codeload.github.com/SiddiqSoft/restcl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248981258,"owners_count":21193143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","cpp20","json-api","nlohmann-json","nuget","rest-client","windows","winhttp"],"created_at":"2024-11-21T21:20:11.603Z","updated_at":"2026-05-01T07:01:27.061Z","avatar_url":"https://github.com/SiddiqSoft.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restcl: A Focused REST Client for Modern C++\n\n\u003c!-- badges --\u003e\n[![Build Status](https://dev.azure.com/siddiqsoft/siddiqsoft/_apis/build/status/SiddiqSoft.restcl?branchName=main)](https://dev.azure.com/siddiqsoft/siddiqsoft/_build/latest?definitionId=13\u0026branchName=main)\n![](https://img.shields.io/nuget/v/SiddiqSoft.restcl)\n![](https://img.shields.io/github/v/tag/SiddiqSoft/restcl)\n![](https://img.shields.io/azure-devops/tests/siddiqsoft/siddiqsoft/13)\n\u003c!-- end badges --\u003e\n\n## Overview\n\n**restcl** is a header-only REST client library for modern C++23 that provides a clean, JSON-first API for interacting with RESTful servers. It abstracts platform-specific HTTP implementations (WinHTTP on Windows, libcurl on Unix/Linux/macOS) behind a unified, modern C++ interface. The library prioritizes simplicity and instructional clarity over performance, making it ideal for applications that need straightforward REST communication without the complexity of lower-level HTTP libraries.\n\n### Key Features\n\n- **JSON-First API**: JSON is a first-class citizen in the API design\n- **Modern C++23**: Leverages C++23 features including `std::expected`, `std::format`, and user-defined literals\n- **Header-Only**: Easy integration with no compilation overhead\n- **Cross-Platform**: Native implementations for Windows (WinHTTP) and Unix/Linux/macOS (libcurl)\n- **User-Defined Literals**: Convenient syntax like `\"https://api.example.com\"_GET`\n- **Async Support**: Non-blocking async operations with callback-based responses\n- **Error Handling**: Uses `std::expected\u003cT, E\u003e` for robust error handling without exceptions for IO operations\n- **Comprehensive Testing**: Extensive test suite with unit, integration, and stress tests\n- **Type-Safe**: Template-based design with support for custom character types\n\n## Table of Contents\n\n- [Quick Start](#quick-start)\n- [Installation](#installation)\n- [Usage Examples](#usage-examples)\n- [Architecture](#architecture)\n- [Dependencies](#dependencies)\n- [Building](#building)\n- [Testing](#testing)\n- [Best Practices](#best-practices)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Quick Start\n\n### Basic GET Request\n\n```cpp\n#include \u003csiddiqsoft/restcl.hpp\u003e\nusing namespace siddiqsoft::restcl_literals;\n\nint main() {\n    auto client = siddiqsoft::GetRESTClient();\n    \n    auto request = \"https://api.example.com/users\"_GET;\n    auto response = client-\u003esend(request);\n    \n    if (response) {\n        std::cout \u003c\u003c \"Status: \" \u003c\u003c response-\u003estatusCode() \u003c\u003c \"\\n\";\n        std::cout \u003c\u003c \"Body: \" \u003c\u003c response-\u003ebody() \u003c\u003c \"\\n\";\n    } else {\n        std::cerr \u003c\u003c \"Error: \" \u003c\u003c response.error() \u003c\u003c \"\\n\";\n    }\n    \n    return 0;\n}\n```\n\n### POST Request with JSON\n\n```cpp\n#include \u003csiddiqsoft/restcl.hpp\u003e\n#include \u003cnlohmann/json.hpp\u003e\n\nusing json = nlohmann::json;\nusing namespace siddiqsoft::restcl_literals;\n\nint main() {\n    auto client = siddiqsoft::GetRESTClient();\n    \n    auto request = \"https://api.example.com/users\"_POST;\n    \n    json payload = {\n        {\"name\", \"John Doe\"},\n        {\"email\", \"john@example.com\"}\n    };\n    \n    request.setBody(payload.dump());\n    request.setHeader(\"Content-Type\", \"application/json\");\n    \n    auto response = client-\u003esend(request);\n    \n    if (response) {\n        auto result = json::parse(response-\u003ebody());\n        std::cout \u003c\u003c \"Created user: \" \u003c\u003c result[\"id\"] \u003c\u003c \"\\n\";\n    }\n    \n    return 0;\n}\n```\n\n### Async Request with Callback\n\n```cpp\n#include \u003csiddiqsoft/restcl.hpp\u003e\n#include \u003catomic\u003e\n\nusing namespace siddiqsoft::restcl_literals;\n\nint main() {\n    auto client = siddiqsoft::GetRESTClient();\n    std::atomic\u003cbool\u003e done{false};\n    \n    auto request = \"https://api.example.com/data\"_GET;\n    \n    client-\u003esendAsync(request, [\u0026done](const auto\u0026 req, auto response) {\n        if (response) {\n            std::cout \u003c\u003c \"Async response: \" \u003c\u003c response-\u003estatusCode() \u003c\u003c \"\\n\";\n        } else {\n            std::cerr \u003c\u003c \"Async error: \" \u003c\u003c response.error() \u003c\u003c \"\\n\";\n        }\n        done = true;\n    });\n    \n    // Wait for async operation to complete\n    while (!done) {\n        std::this_thread::sleep_for(std::chrono::milliseconds(10));\n    }\n    \n    return 0;\n}\n```\n\n## Installation\n\n### Via NuGet (Windows)\n\n```bash\nnuget install SiddiqSoft.restcl\n```\n\n### Via CMake (Recommended)\n\nAdd to your `CMakeLists.txt`:\n\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(restcl\n    GIT_REPOSITORY https://github.com/SiddiqSoft/restcl.git\n    GIT_TAG main\n)\n\nFetchContent_MakeAvailable(restcl)\n\ntarget_link_libraries(your_target PRIVATE restcl::restcl)\n```\n\n### Manual Integration\n\n1. Clone the repository\n2. Copy the `include/siddiqsoft` directory to your project\n3. Ensure your compiler supports C++23\n4. Link against platform-specific libraries:\n   - **Windows**: WinHTTP (included in Windows SDK)\n   - **Unix/Linux/macOS**: libcurl\n\n## Usage Examples\n\n### Supported HTTP Methods\n\nThe library provides user-defined literals for all standard HTTP methods:\n\n```cpp\nusing namespace siddiqsoft::restcl_literals;\n\nauto get_req = \"https://api.example.com/resource\"_GET;\nauto post_req = \"https://api.example.com/resource\"_POST;\nauto put_req = \"https://api.example.com/resource/123\"_PUT;\nauto delete_req = \"https://api.example.com/resource/123\"_DELETE;\nauto patch_req = \"https://api.example.com/resource/123\"_PATCH;\nauto head_req = \"https://api.example.com/resource\"_HEAD;\nauto options_req = \"https://api.example.com/resource\"_OPTIONS;\n```\n\n### Working with Headers\n\n```cpp\nauto request = \"https://api.example.com/data\"_GET;\n\nrequest.setHeader(\"Authorization\", \"Bearer token123\");\nrequest.setHeader(\"Accept\", \"application/json\");\nrequest.setHeader(\"User-Agent\", \"MyApp/1.0\");\n\n// Access headers\nauto auth = request.getHeader(\"Authorization\");\n```\n\n### Request Configuration\n\n```cpp\nauto client = siddiqsoft::GetRESTClient({\n    {\"connectTimeout\", 3000},      // Connection timeout in ms\n    {\"timeout\", 5000},             // Overall timeout in ms\n    {\"userAgent\", \"MyApp/1.0\"},    // Custom user agent\n    {\"trace\", false}               // Enable/disable tracing\n});\n```\n\n### Error Handling\n\nThe library uses `std::expected\u003cT, E\u003e` for error handling:\n\n```cpp\nauto response = client-\u003esend(request);\n\nif (response) {\n    // Success path\n    std::cout \u003c\u003c \"Status: \" \u003c\u003c response-\u003estatusCode() \u003c\u003c \"\\n\";\n} else {\n    // Error path\n    int error_code = response.error();\n    std::cerr \u003c\u003c \"Request failed with error: \" \u003c\u003c error_code \u003c\u003c \"\\n\";\n}\n```\n\n### JSON Integration\n\n```cpp\n#include \u003cnlohmann/json.hpp\u003e\n\nusing json = nlohmann::json;\n\n// Parse response as JSON\nauto response = client-\u003esend(request);\nif (response \u0026\u0026 response-\u003estatusCode() == 200) {\n    auto data = json::parse(response-\u003ebody());\n    \n    // Access JSON data\n    std::string name = data[\"name\"];\n    int age = data[\"age\"];\n}\n```\n\n## API Reference\n\nFor comprehensive API documentation, see [API.md](API.md).\n\n## Architecture\n\n### Project Structure\n\n```\nrestcl/\n├── include/siddiqsoft/\n│   ├── restcl.hpp                    # Main public header (platform dispatcher)\n│   └── private/\n│       ├── basic_restclient.hpp      # Abstract base class for REST clients\n│       ├── http_frame.hpp            # Base class for HTTP requests/responses\n│       ├── rest_request.hpp          # REST request model with literals support\n│       ├── rest_response.hpp         # REST response model with parsing\n│       ├── restcl_unix.hpp           # libcurl-based implementation\n│       └── restcl_win.hpp            # WinHTTP-based implementation\n├── tests/                            # Comprehensive test suite\n│   ├── test_validation.cpp           # Validation and error handling tests\n│   ├── test_restcl.cpp               # Core functionality tests\n│   ├── test_serializers.cpp          # JSON serialization tests\n│   ├── test_postbin.cpp              # Integration tests with external services\n│   ├── test_libcurl_helpers.cpp      # Unix/Linux-specific tests\n│   └── test_mock_and_coverage.cpp    # Mock and coverage tests\n├── docs/                             # Doxygen documentation\n├── pack/                             # NuGet packaging and build helpers\n├── CMakeLists.txt                    # Main CMake configuration\n├── CMakePresets.json                 # CMake presets for builds\n├── .clang-format                     # Code formatting rules\n├── .clang-tidy                       # Static analysis configuration\n├── best_practices.md                 # Comprehensive development guidelines\n└── azure-pipelines.yml               # CI/CD pipeline\n```\n\n### Core Components\n\n#### `basic_restclient\u003cCharT\u003e`\nAbstract interface defining the REST client contract with `send()` and `sendAsync()` methods.\n\n#### `http_frame\u003cCharT\u003e`\nBase class providing common HTTP functionality including headers, content, and protocol version management.\n\n#### `rest_request\u003cCharT\u003e`\nExtends `http_frame` with request-specific encoding and HTTP method support.\n\n#### `rest_response\u003cCharT\u003e`\nExtends `http_frame` with response parsing, status codes, and reason phrases.\n\n#### Platform-Specific Implementations\n- **`HttpRESTClient`**: Unix/Linux/macOS implementation using libcurl\n- **`WinHttpRESTClient`**: Windows implementation using WinHTTP with HTTP/2 support\n\n## Dependencies\n\n### Core Dependencies\n\n| Dependency | Version | Purpose |\n|-----------|---------|---------|\n| nlohmann/json | v3.12.0 | JSON parsing and serialization |\n| SplitUri | v3.0.0 | URI parsing and manipulation |\n| AzureCppUtils | v3.2.5 | Azure-specific utilities |\n| string2map | v2.5.0 | String-to-map conversion utilities |\n| RunOnEnd | v1.4.2 | RAII-based cleanup utilities |\n| asynchrony | v2.1.1 | Asynchronous operation helpers |\n| acw32h | v2.7.4 | Windows-specific C++ wrapper for WinHTTP (Windows only) |\n| CURL | v8.7+ | libcurl for Unix/Linux/macOS |\n\n### Build Tools\n\n| Tool | Version | Purpose |\n|------|---------|---------|\n| CMake | v3.29+ | Build system |\n| Clang-Format | Latest | Code formatting |\n| Clang-Tidy | Latest | Static analysis |\n| Google Test | v1.17.0 | Testing framework |\n| Doxygen | Latest | Documentation generation |\n\n### Compiler Requirements\n\n- **C++23 Standard**: Required\n- **Visual Studio 2022**: For Windows builds (MSVC)\n- **Clang 18+** or **GCC 13+**: For Unix/Linux builds\n- **Clang on macOS**: With `-fexperimental-library` flag for `std::stop_token` and `std::jthread`\n\n## Building\n\n### Prerequisites\n\n- CMake 3.29 or later\n- C++23 compatible compiler\n- Platform-specific dependencies:\n  - **Windows**: Windows SDK (includes WinHTTP)\n  - **Linux**: libcurl development libraries (`libcurl-devel` or `libcurl4-openssl-dev`)\n  - **macOS**: libcurl (usually pre-installed)\n\n### Build Steps\n\n```bash\n# Clone the repository\ngit clone https://github.com/SiddiqSoft/restcl.git\ncd restcl\n\n# Configure with CMake\ncmake --preset default -DRESTCL_BUILD_TESTS=ON\n\n# Build the project\ncmake --build --preset default\n\n# Run tests (optional)\nctest --preset default\n```\n\n### CMake Options\n\n- `RESTCL_BUILD_TESTS`: Enable/disable test suite (default: OFF)\n- `CMAKE_BUILD_TYPE`: Debug or Release (default: Release)\n\n## Testing\n\nThe library includes a comprehensive test suite covering:\n\n### Test Categories\n\n- **Unit Tests** (`test_validation.cpp`): Request/response validation, error handling, edge cases\n- **Core Tests** (`test_restcl.cpp`): Core functionality, async operations, multiple HTTP verbs, stress tests\n- **Serialization Tests** (`test_serializers.cpp`): JSON serialization and deserialization\n- **Integration Tests** (`test_postbin.cpp`): Real HTTP calls to external services\n- **Platform-Specific Tests** (`test_libcurl_helpers.cpp`): Unix/Linux-specific libcurl tests\n- **Mock Tests** (`test_mock_and_coverage.cpp`): Mock objects and code coverage validation\n\n### Running Tests\n\n```bash\n# Build with tests enabled\ncmake --preset default -DRESTCL_BUILD_TESTS=ON\ncmake --build --preset default\n\n# Run all tests\nctest --preset default\n\n# Run specific test\nctest --preset default -R test_restcl\n```\n\n### Test Coverage\n\n- ASAN (Address Sanitizer) and leak detection enabled for Debug builds on Linux/Clang\n- Code coverage instrumentation enabled for Debug builds\n- Tests pass on both Windows (MSVC) and Unix/Linux (Clang/GCC)\n\n## Best Practices\n\nFor comprehensive guidance on code style, testing strategies, common patterns, and best practices when working with or extending this library, see [best_practices.md](best_practices.md).\n\n### Key Principles\n\n#### Error Handling\n- Use `std::expected\u003cT, E\u003e` for IO operations instead of exceptions\n- Throw `std::invalid_argument` for validation errors\n- Different platforms return different error codes:\n  - Windows: WinHTTP error codes (12001, 12002, 12029, etc.)\n  - Unix/Linux: POSIX error codes (ECONNRESET, etc.)\n\n#### Modern C++ Features\n- Leverage C++23 features: `std::expected`, `std::format`, `std::atomic`, concepts\n- Use move semantics extensively\n- Prefer `std::shared_ptr` for shared ownership\n- Use `[[nodiscard]]` on functions returning important values\n\n#### Async Operations\n- Use callbacks for async operations: `std::function\u003cvoid(rest_request\u003c\u003e\u0026, std::expected\u003crest_response\u003c\u003e, int\u003e)\u003e`\n- Callbacks receive both request and response (or error code)\n- Register global callbacks via `configure()` and override per-request\n- Use `std::atomic\u003cbool\u003e` with `.wait()` and `.notify_all()` for test synchronization\n\n#### Code Style\n- Classes: PascalCase (e.g., `rest_request`, `HttpRESTClient`)\n- Functions: camelCase (e.g., `setMethod()`, `getUri()`)\n- Constants: UPPER_SNAKE_CASE (e.g., `HTTP_NEWLINE`)\n- Private members: Prefix with underscore (e.g., `_statusCode`)\n- Namespaces: lowercase (e.g., `siddiqsoft`, `restcl_literals`)\n\n#### Documentation\n- Use Doxygen comments (`///` or `/**`) for public APIs\n- Include `@brief`, `@param`, `@return`, `@throw` tags\n- Comment non-obvious algorithms or platform-specific code\n- Guard debug output with `#if defined(DEBUG)`\n\n## Design Philosophy\n\n### Motivation\n\nDesign a library where JSON is a first-class API metaphor for interacting with RESTful servers.\n\n### Core Principles\n\n1. **Focused Scope**: REST interactions with JSON only. This limitation allows us to simplify usage and make it feel very C++ instead of the C-like API of Win32 or LibCURL.\n\n2. **Modern C++**: C++23 is required, enabling:\n   - Visual Studio 2022 on Windows\n   - WinHTTP library with HTTP/2 support\n   - Modern language features and idioms\n\n3. **Header-Only**: Easy integration with no compilation overhead for the library itself.\n\n4. **Native Implementations**: Use platform-specific libraries for actual IO:\n   - Windows: WinHTTP library\n   - Unix/Linux/macOS: libcurl\n\n5. **User-Defined Literals**: Support for convenient syntax like `_GET`, `_DELETE`, etc. via the `siddiqsoft::restcl_literals` namespace.\n\n6. **Instructional**: Use as little code as necessary and be clear about intent.\n\n7. **Interface-Focused**: The focus is on the interface to the end user, not internal complexity.\n\n8. **Simplicity Over Performance**: Hide the underlying implementation and prioritize clarity.\n\n## Roadmap\n\n- [ ] Performance optimizations\n- [ ] Additional test coverage\n- [ ] Extended documentation with more examples\n- [ ] Support for additional content types\n- [ ] Enhanced error diagnostics\n\n## Contributing\n\nContributions are welcome! Please ensure:\n\n1. Code follows the style guidelines in [best_practices.md](best_practices.md)\n2. All tests pass: `ctest --preset default`\n3. New features include appropriate tests\n4. Documentation is updated accordingly\n5. Code is formatted with clang-format: `clang-format -i \u003cfile\u003e`\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Support\n\nFor issues, questions, or suggestions:\n\n1. Check the [best_practices.md](best_practices.md) for comprehensive guidance\n2. Review existing [GitHub Issues](https://github.com/SiddiqSoft/restcl/issues)\n3. Create a new issue with detailed information\n4. For security concerns, please email privately\n\n## Acknowledgments\n\n- Built with modern C++23 features\n- Uses [nlohmann/json](https://github.com/nlohmann/json) for JSON handling\n- Cross-platform support via WinHTTP and libcurl\n- Comprehensive testing with Google Test framework\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiddiqsoft%2Frestcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsiddiqsoft%2Frestcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsiddiqsoft%2Frestcl/lists"}