Skip to content

A user friendly, easy to use http client based on the C# HttpClient class. This repository contains the source code for my NuGet package. The class library is built on .NET Standard 2.0, ensuring compatibility with both legacy and modern projects.

License

Notifications You must be signed in to change notification settings

aurel192/EasyHttpsClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyHttpsClient

v2.0.0

EasyHttpsClient is a simple and easy-to-use HTTP client library for .NET, .NET Core and .NET Framework
It provides an easier syntax for sending GET, POST, PUT, DELETE requests and retrieving response data.

Work In Progress:
Different endpoint requires various requests.
Feel Free to submit issues or pull requests on GitHub aurel192 - EasyHttpsClient repository


Links

GitHub aurel192 - EasyHttpsClient repository

NuGet Package - EasyHttpsClient


Usage


Setting / Adding - Headers, Timeout, Encoding, and more...

client.AddToRequestHeaders("Authorization", "Bearer token / ApiKey / etc ...");
client.SetTimeout(10);
client.SetEncoding(Encoding.UTF8);

GET:

var getClient = new HttpGetClient();
getClient.SetUrl($"{BaseUrl}/api/TestItems/");   

// It will just send the request
await getClient.SendAsync();

// This line will read the result as string
string responseString = await getClient.ReadResultAsStringAsync();

// or byte array
byte[] responseByteArray = await getClient.ReadResultAsByteArrayAsync();

Console.WriteLine(response);

// You can access the raw HttpResponseMessage if you need it for some reason
HttpResponseMessage httpResponseMessage = getClient.GetHttpResponseMessage();

POST:

var postClient = new HttpPostClient();
postClient.SetTimeout(10);
postClient.SetEncoding(Encoding.UTF8);

// POST FormUrlEncodedContent
postClient.SetUrl("https://www.example.com/api/PostKeyValuePairsHere/");
postClient.AddBodyPostData("key1", "value1");
postClient.AddBodyPostData("key2", "value2");

// POST StringContent
var payloadObject = new
{
    key = "NEW ITEM KEY",
    value = "NEW NEW",
    value2 = "BRAND NEW TEST ITEM",
    boolean = true,
};   

// Note: it can be any serializable object
postClient.SetBodyRequestData(payloadObject);   

// Or as Json string
// Note: it can be any format (e.g. XML, ...) depending on the endpoint
string payloadJson = @"{""key"": ""NEW ITEM KEY"",""value"": ""NEW NEW"",""value2"": ""BRAND NEW TEST ITEM"",""boolean"": true}";    

postClient.SetBodyRequestJson(payloadJson);

await postClient.SendAsync();

string responseString = await postClient.ReadResultAsStringAsync();

PUT

var putClient = new HttpPutClient();
putClient.SetUrl($"{BaseUrl}/api/TestItems/1");

var modifiedObject = new
{
    key = "THIS IS NOT THE ORIGINAL",
    value = "IT WILL MODIFY",
    value2 = "MODIFY THE FIRST ELEMENT",
    boolean = true,
};   

putClient.SetBodyRequestData(payloadObject);   

await putClient.SendAsync();   

string responseString = await putClient.ReadResultAsStringAsync();

DELETE

var deleteClient = new HttpDeleteClient();   

deleteClient.SetUrl($"{BaseUrl}/api/TestItems/15");   

await deleteClient.SendAsync();   

string responseString = await deleteClient.ReadResultAsStringAsync();   

License

This library is licensed under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome.
Submit issues or pull requests on GitHub aurel192 - EasyHttpsClient repository

About

A user friendly, easy to use http client based on the C# HttpClient class. This repository contains the source code for my NuGet package. The class library is built on .NET Standard 2.0, ensuring compatibility with both legacy and modern projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages