{"id":25290963,"url":"https://github.com/salixzs/restclient","last_synced_at":"2026-02-18T12:31:29.713Z","repository":{"id":65602175,"uuid":"381045597","full_name":"salixzs/RestClient","owner":"salixzs","description":"Client to REST service from C# (backend) code with IHttpClientFactory. Shortcut HttpMethod extensions and path/query parameter helper classes.","archived":false,"fork":false,"pushed_at":"2025-01-15T14:42:52.000Z","size":251,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-22T14:42:23.057Z","etag":null,"topics":["api-client","httpclient","httpclientfactory","webapiclient"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/salixzs.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,"zenodo":null}},"created_at":"2021-06-28T13:42:17.000Z","updated_at":"2025-01-15T14:42:54.000Z","dependencies_parsed_at":"2023-11-26T14:28:26.012Z","dependency_job_id":"ff50c1b7-07f9-4e9c-a4cd-aeafd25a1828","html_url":"https://github.com/salixzs/RestClient","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/salixzs/RestClient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salixzs%2FRestClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salixzs%2FRestClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salixzs%2FRestClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salixzs%2FRestClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/salixzs","download_url":"https://codeload.github.com/salixzs/RestClient/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/salixzs%2FRestClient/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263218768,"owners_count":23432550,"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":["api-client","httpclient","httpclientfactory","webapiclient"],"created_at":"2025-02-13T00:51:22.801Z","updated_at":"2025-10-14T04:36:25.311Z","avatar_url":"https://github.com/salixzs.png","language":"C#","funding_links":["https://www.buymeacoffee.com/salixzs"],"categories":[],"sub_categories":[],"readme":"# Salix.RestClient\n\nWrapper around IHttpClientFactory HttpClient in System.Net.Http (Core 3+) to provide easier access to RESTful APIs from backend .Net code.\\\nPackage provides abstract base class for any of 3 usage types - with Factory, Named client/factory and Typed client to be used to implement your own REST service HttpClient.\\\nIncluded HttpClient extensions - shortcuts to do  GET, POST, PUT, PATCH and DELETE operations with variety of parameters.\\\nOperations can return raw `HttpResponseMessage` or directly deserialized - typed data object. Internally it uses Json.Net (default) which can be switched to use `System.Text.Json` deserializer.\nAs parameters you can supply path variables and/or query parameters in addition to data content. These are wrapped into own managing objects to simplify their usage.\\\nExample:\n\n```text\n/api/parents/{id}/children/{childId}?skip=0\u0026take=10\n```\ncan be executed as this GET extension method call, returning strongly typed `DomainObject`:\n```c#\nvar result = await _client.GetAsync\u003cDomainObject\u003e(\"/api/parents/{id}/children/{childId}\", new PathParameters(\"id\", 12, \"childId\", 15), new QueryParameters(new { skip = 0, take = 10 })\n```\n\nPackage expects it to have concrete settings object, from witch it gathers `BaseAddress`, [optionally] factory name, authentication approach, any default headers (\"text/json\" is added by default, if not specified implicitly).\\\nCustom `RestClientException` is thrown on failures, containing all the information about request failure.\\\nBuilt in timer will get you execution time you can read after each request for any monitoring needs.\\\nDevelopment time verbose logging will output plenty of details on internal work to logging output (Use Debug() to see it in Visual Studio output window).\n\n[![Build](https://github.com/salixzs/RestClient/actions/workflows/build_test.yml/badge.svg?branch=main)](https://https://github.com/salixzs/RestClient/actions/workflows/build_test.yml) [![Nuget version](https://img.shields.io/nuget/v/Salix.RestClient.svg)](https://www.nuget.org/packages/Salix.RestClient/) [![NuGet Downloads](https://img.shields.io/nuget/dt/Salix.RestClient.svg)](https://www.nuget.org/packages/Salix.RestClient/)\n\n\n## Usage\n\n\u003e More detailed documentation is in [Wiki](https://github.com/salixzs/RestClient/wiki).\n\nCreate your own API client class, deriving from `AbstractRestClient` class and use any of four constructors, depending on your approach - constructors with IHttpClientFactory for factory or named approaches or constructors with HttpClient instance for typed clients.\n\n```csharp\npublic class MyServiceClient : AbstractRestClient\n{\n    /// \u003csummary\u003e\n    /// Client to work with MyService API. Here assumed typed client implementation/setup with default Json.Net serizalizer.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"httpClient\"\u003eThe HTTP client (.Net Framework).\u003c/param\u003e\n    /// \u003cparam name=\"parameters\"\u003eThe parameters/settings for MyService API client.\u003c/param\u003e\n    /// \u003cparam name=\"logger\"\u003eThe logging object (ILogger in MS.Extensions.Logging).\u003c/param\u003e\n    public MyServiceClient(HttpClient httpClient, MyServiceClientSettings parameters, ILogger\u003cMyServiceClient\u003e logger)\n        : base(httpClient, parameters, logger)\n    {\n    }\n}\n```\n\nClient needs settings to be defined (derived from `RestServiceSettings`) to know where and how to connect to API:\n\n```csharp\n// Yepp. Nothing required for this class if nothing special is needed.\npublic class MyServiceClientSettings : RestServiceSettings\n{\n}\n```\n\nFor this you need to create this class instance supplying base class property values (from configuration). The only required property to set is `BaseAddress`. All other are optional if you want to change authentication mechanism or add some default header key-values for all API calls.\n\n```csharp\nnew MyServiceClientSettings {\n    BaseAddress = \"https://api.myservice.com\",\n    Authentication = new RestServiceAuthentication\n    {\n        AuthenticationType = ApiAuthenticationType.Basic,\n        UserName = \"apiuser\",\n        Password = \"secret\"\n    },\n    FactoryName = \"namedClient\",\n    RequestHeaders = new Dictionary\u003cstring, string\u003e { { \"version\", \"2.0\" } }\n}\n```\n\nUsing MS Extensions for Dependency Injection, register them appropriately\n\n```csharp\nservices.AddHttpClient\u003cMyServiceClient\u003e(); // This registers IHttpClientFactory with typed client\nservices.AddSingleton(myServiceClientSettings); // instance of configuration for API client\n```\n\nThen use client injected instance in your logic/controller/handler classes:\n\n```csharp\npublic class BusinessLogic\n{\n    private readonly MyServiceClient _api;\n    \n    // ctor\n    public BusinessLogic(MyServiceClient apiClient) =\u003e _api = apiClient;\n    \n    public async Task LogicMethod() \n    {\n        var receivedData = await _api.GetAsync\u003cMyData\u003e(\"endpoint/data/uri\");\n    }\n}\n```\n\n\n\n### Like what I created?\n\nPut a star to repository or better - \n\n\u003ca href=\"https://www.buymeacoffee.com/salixzs\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: 32px !important;width: 146px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;\" \u003e\u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalixzs%2Frestclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalixzs%2Frestclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalixzs%2Frestclient/lists"}