{"id":16352155,"url":"https://github.com/bugthesystem/httwrap","last_synced_at":"2025-03-21T00:31:05.481Z","repository":{"id":26567695,"uuid":"30021810","full_name":"bugthesystem/Httwrap","owner":"bugthesystem","description":"General purpose, simple but useful HttpClient wrapper for .NET \u0026 Xamarin/Mono","archived":false,"fork":false,"pushed_at":"2017-09-25T20:51:22.000Z","size":912,"stargazers_count":46,"open_issues_count":1,"forks_count":11,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-11T02:08:40.369Z","etag":null,"topics":["c-sharp","http-client","mono","xamarin"],"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/bugthesystem.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}},"created_at":"2015-01-29T13:46:05.000Z","updated_at":"2024-10-29T18:28:04.000Z","dependencies_parsed_at":"2022-09-14T04:01:54.732Z","dependency_job_id":null,"html_url":"https://github.com/bugthesystem/Httwrap","commit_stats":null,"previous_names":["bugthesystem/httwrap","ziyasal/httwrap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugthesystem%2FHttwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugthesystem%2FHttwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugthesystem%2FHttwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugthesystem%2FHttwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugthesystem","download_url":"https://codeload.github.com/bugthesystem/Httwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244094274,"owners_count":20397020,"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":["c-sharp","http-client","mono","xamarin"],"created_at":"2024-10-11T01:25:10.114Z","updated_at":"2025-03-21T00:31:05.056Z","avatar_url":"https://github.com/bugthesystem.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Httwrap\nGeneral purpose, simple but useful HttpClient wrapper for .NET \u0026 Xamarin/Mono\n\n[![Build status](https://ci.appveyor.com/api/projects/status/vyg8a2lsw1jf9nki?svg=true)](https://ci.appveyor.com/project/ziyasal/httwrap)[![Coverage Status](https://coveralls.io/repos/ziyasal/Httwrap/badge.svg)](https://coveralls.io/r/ziyasal/Httwrap)\n\n## How to use\n\n### Install\n\n```cs\nPM\u003e Install-Package Httwrap\n```\n\n### Init\n\n```csharp\n  IHttwrapConfiguration configuration = new HttwrapConfiguration(\"http://localhost:9000/\");\n  IHttwrapClient _httwrap = new HttwrapClient(configuration);\n```\n\n### GET\n\n#### Basic\n\n```csharp\nIHttwrapResponse\u003cProduct\u003e response = await _httwrap.GetAsync\u003cProduct\u003e(\"api/products/1\");\nDump(response.Data);\nDump(response.StatusCode);\n```\n\n#### With QueryString\n\n*_It supports `DataMember` and `IgnoreDataMember` attributes._*\n\n```csharp\n/*\npublic class FilterRequest\n{\n  [DataMember(Name = \"cat\")]\n  public string Category { get; set; }\n  \n  public int NumberOfItems { get; set; }\n}\n*/\n\nvar payload = new FilterRequest\n{\n  Category = \"Shoes\",\n  NumberOfItems = 10\n};\n\n//Url: api/test?cat=Shoes\u0026NumberOfItems=10\nIHttwrapResponse\u003cList\u003cProduct\u003e\u003e response =\n                            await _client.GetAsync\u003cList\u003cProduct\u003e\u003e(\"api/test\", payload);\n\nDump(response.Data);\nDump(response.StatusCode);\n```\n\n#### Serialize response\n\n```csharp\nIHttwrapResponse response = await _httwrap.GetAsync(\"api/products\");\nList\u003cProduct\u003e values = response.ResultAs\u003cList\u003cProduct\u003e\u003e();\nDump(response.StatusCode);\n\n/* ResultAs\u003cT\u003e() extension method uses Newtonsoft.Json serializer by default.  \nTo use your own serializer set JExtensions.Serializer = new YourCustomSerializerImpl();*/\n```\n\n### POST\n\n```csharp\nProduct product = new Product{ Name= \"Product A\", Quantity = 3 };\nIHttwrapResponse response = await _httwrap.PostAsync\u003cProduct\u003e(\"api/products\",product);\nDump(response.StatusCode);\n```\n\n### PUT\n\n```csharp\nProduct product = new Product{ Name= \"Product A\", Quantity = 3 };\nIHttwrapResponse response = await _httwrap.PutAsync\u003cProduct\u003e(\"api/products/1\",product);\nDump(response.StatusCode);\n```\n\n### PATCH\n\n```csharp\nProduct product = new Product{ Name= \"Product A\", Quantity = 3};\nIHttwrapResponse response = await _httwrap.PatchAsync\u003cProduct\u003e(\"api/products/1\",product);\nDump(response.StatusCode);\n```\n\n### DELETE\n\n```csharp\nIHttwrapResponse response = await _httwrap.DeleteAsync(\"api/products/1\");\nDump(response.StatusCode);\n```\n\n\n### Error Handler\n\n```csharp\nIHttwrapResponse\u003cList\u003cProduct\u003e\u003e response =\n      await _httwrap.GetAsync\u003cList\u003cProduct\u003e\u003e(\"api/products\", (statusCode, body) =\u003e\n      {\n        _logger.Error(\"Body :{0}, StatusCode :{1}\", body, statusCode);\n      });\n```\n\n### Auth\n\n#### Basic Credentials\n\n```csharp\nIHttwrapConfiguration configuration = new HttwrapConfiguration(\"http://localhost:9000/\")\n{\n  Credentials = new BasicAuthCredentials(\"user\", \"s3cr3t\")\n};\nIHttwrapClient _httwrap = new HttwrapClient(configuration);\n```\n\n#### OAuth Credentials\n\n_**Use existing ```token```**_\n```csharp\nIHttwrapConfiguration configuration = new HttwrapConfiguration(\"http://localhost:9000/\")\n{\n  Credentials = new OAuthCredentials(\"token\")\n};\nIHttwrapClient _httwrap = new HttwrapClient(configuration);\n```\n\n_**Use Username / password to get token from ```edpoint```**_\n\n```csharp\nIHttwrapConfiguration configuration = new HttwrapConfiguration(\"http://localhost:9000/\")\n{\n  Credentials = new OAuthCredentials(\"us3r\", \"p4ssw0rd\", BaseAddress + \"/token\")\n};\nIHttwrapClient _httwrap = new HttwrapClient(configuration);\n```\n\n### Req/Res Interceptor\n\n```csharp\npublic class DummyInterceptor : IHttpInterceptor\n{\n    private readonly IHttwrapClient _client;\n\n    public void OnRequest(HttpRequestMessage request)\n    {\n    }\n\n   public void OnResponse(HttpRequestMessage request, HttpResponseMessage response)\n   {\n      response.StatusCode = HttpStatusCode.Accepted;\n   }\n}\nclient.AddInterceptor(new DummyInterceptor());\n```\n\n## Bugs\n\nIf you encounter a bug, performance issue, or malfunction, please add an [Issue](https://github.com/ziyasal/Httwrap/issues) with steps on how to reproduce the problem.\n\n## TODO\n\n- Add more tests\n- Add more documentation\n\n## License\n\nCode and documentation are available according to the *MIT* License (see [LICENSE](https://github.com/ziyasal/Httwrap/blob/master/LICENSE)).\n\n@ziλasal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugthesystem%2Fhttwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugthesystem%2Fhttwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugthesystem%2Fhttwrap/lists"}