https://github.com/ethern-myth/efetch
efetch is a lightweight C# library for making HTTP requests with ease. It provides a simple interface for performing common HTTP operations such as GET, POST, PUT, PATCH, and DELETE. It also supports custom logging for requests, responses, and errors.
https://github.com/ethern-myth/efetch
csharp dotnet httpclient netcore restapi sdk singleton
Last synced: 20 days ago
JSON representation
efetch is a lightweight C# library for making HTTP requests with ease. It provides a simple interface for performing common HTTP operations such as GET, POST, PUT, PATCH, and DELETE. It also supports custom logging for requests, responses, and errors.
- Host: GitHub
- URL: https://github.com/ethern-myth/efetch
- Owner: Ethern-Myth
- License: mit
- Created: 2024-03-13T12:13:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-14T12:38:08.000Z (over 1 year ago)
- Last Synced: 2025-03-19T20:46:57.925Z (8 months ago)
- Topics: csharp, dotnet, httpclient, netcore, restapi, sdk, singleton
- Language: C#
- Homepage:
- Size: 187 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# efetch
**efetch** is a lightweight C# library for performing resilient HTTP requests with minimal boilerplate. It supports GET, POST, PUT, PATCH, DELETE operations, built-in retry policies via Polly, customizable headers, and optional structured logging.


---
## ๐ Installation
Install via NuGet Package Manager:
```bash
Install-Package efetch
```
Or via .NET CLI:
```bash
dotnet add package efetch
```
---
## โจ Features
- โ
Clean abstraction with `IEfetch` interface
- ๐ Retry support using Polly
- ๐ฆ JSON deserialization with support for primitives, objects, and arrays
- ๐ก Simple query parameter handling
- ๐ Optional request/response logging
- ๐งฉ Built-in support for dependency injection
---
## ๐งฉ Configuration
Add to your app's `appsettings.json`:
```json
"Efetch": {
"BaseUrl": "https://api.example.com",
"DefaultHeaders": {
"Authorization": "Bearer YOUR_TOKEN",
"Accept": "application/json"
},
"RetryCount": 3
}
```
Register `Efetch` in your DI container (`Program.cs`):
```csharp
builder.Services.AddEfetch(builder.Configuration);
```
---
## ๐งช Usage
### Inject `IEfetch`:
```csharp
public class VaultController : ControllerBase
{
private readonly IEfetch _efetch;
public VaultController(IEfetch efetch)
{
_efetch = efetch;
}
[HttpGet]
public async Task Get([FromQuery] string key)
{
var result = await _efetch.GetAsync("vault", null, new() { { "key", key } });
return Ok(result);
}
}
```
---
## ๐ฆ Example
```csharp
public class MyService
{
private readonly IEfetch _efetch;
public MyService(IEfetch efetch)
{
_efetch = efetch;
}
public async Task RunAsync()
{
// GET example
var result = await _efetch.GetAsync("/data");
// POST example
var body = new MyRequest { Name = "John" };
var response = await _efetch.PostAsync("/create", body);
// String response example
var plainText = await _efetch.GetAsync("/version");
}
}
```
---
## ๐ API
### `IEfetch`
- `GetAsync(...)`
- `PostAsync(...)`
- `PutAsync(...)`
- `PatchAsync(...)`
- `DeleteAsync(...)`
All methods support:
- Optional headers
- Optional query parameters
- Optional ID for REST-style routes
- Built-in retry policy
### `ILoggingProvider`
Optionally implement your own logger or use the built-in `ConsoleLoggingProvider`.
---
## ๐ง Advanced: Manual Configuration
```csharp
builder.Services.AddSingleton(new EfetchConfig
{
BaseUrl = "https://api.example.com",
DefaultHeaders = new()
{
{ "Authorization", "Bearer abc123" },
{ "Accept", "application/json" }
}
});
builder.Services.AddTransient();
```
---
## ๐ค Author
**efetch** is created by [Ethern Myth](https://github.com/Ethern-Myth).
---
## ๐ License
Licensed under the [MIT License](https://opensource.org/licenses/MIT).