MakeEasy.RestClient
0.11.4
dotnet add package MakeEasy.RestClient --version 0.11.4
NuGet\Install-Package MakeEasy.RestClient -Version 0.11.4
<PackageReference Include="MakeEasy.RestClient" Version="0.11.4" />
<PackageVersion Include="MakeEasy.RestClient" Version="0.11.4" />
<PackageReference Include="MakeEasy.RestClient" />
paket add MakeEasy.RestClient --version 0.11.4
#r "nuget: MakeEasy.RestClient, 0.11.4"
#:package MakeEasy.RestClient@0.11.4
#addin nuget:?package=MakeEasy.RestClient&version=0.11.4
#tool nuget:?package=MakeEasy.RestClient&version=0.11.4
MakeEasy.RestClient
Project Description
This is an easy-to-use RESTful or Rest Web API client library. It's a wrapper of HttpClient. The goal of this library is to be very MakeEasy to use. Any suggestions or improvements to the project are welcome.
How to use
Post
- Post json object
using var client = new RestClient("https://api.example.com");
var response = await client.PostAsync("/Person/Insert", new { name = "John", age = 30 });
In none-generic version, it will throw an exception if there's an error in network/framework. You need to check the response status code and content by yourself. For example:
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
- if you want to pass query parameters, you can use Options to generate the url.
var reponse = await client.PostAsync(
"/Person/Insert",
new { name = "John", age = 30 },
new SendOptions {
QueryParams = new {some properties})
}
);
- Post MultiPart
var multipart = new MultipartFormDataContent();
multipart.Add(new StringContent("value1"), "key1");
multipart.Add(new StringContent("value2"), "key2");
var fs = new FileStream("path/to/file.txt", FileMode.Open);
multipart.Add(new StreamContent(fs), "file", "file.txt");
var reponse = await client.PostMultipartAsync("/Person/Insert", multiPart);
- Post pure string as body
var body = """
{
"name"="John",
"age"=30
}
""";
var reponse = await client.PostStringAsync("/Person/Insert", body, RestContentTypes.Json);
- Generic Post
var count = await client.PostAsync<int>("/Person/Insert", new { name = "John", age = 30 });
Console.WriteLine($"inserted count: {count}");
In generic version, it will throw an exception if there's an error in network/framework or status code. You don't need to check the response status code generally.
Get
var person = await client.GetAsync<Person>("/Person/FindByName", new { name = "John" });
Other Methods
Other methods like Put/Delete/Patch/Options/Head are similar to Post and Get.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.5.2
- Newtonsoft.Json (>= 13.0.1)
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Add HttpMessageHandler at RestClient creator