DotEmilu 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotEmilu --version 1.0.0
                    
NuGet\Install-Package DotEmilu -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotEmilu" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotEmilu" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DotEmilu" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotEmilu --version 1.0.0
                    
#r "nuget: DotEmilu, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotEmilu@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotEmilu&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DotEmilu&version=1.0.0
                    
Install as a Cake Tool

DotEmilu

A simple, easy-to-use .NET library designed for handling HTTP requests and responses.

Features

  • Supports GET, POST, PUT, and DELETE requests.
  • Handles HTTP responses with status codes and error handling.
  • Built with .NET 8 for cross-platform compatibility (Windows, Linux, macOS).
  • Supports async/await for non-blocking HTTP calls.

How to Use

Build your logic from your previously created request and expected response

public class SampleUseCase(IVerifier<SampleRequest> verifier, IPresenter presenter)
    : Handler<SampleRequest, SampleResponse>(verifier, presenter)
{
    private readonly IPresenter _presenter = presenter;
    private readonly IVerifier<SampleRequest> _verifier = verifier;

    protected override async Task<SampleResponse?> HandleResponseAsync(SampleRequest request,
        CancellationToken cancellationToken = default)
    {
        var result = await SomeMethod(request, cancellationToken);

        // Add custom validations
        if (string.IsNullOrEmpty(request.Note))
        {
            _verifier.AddError("request", "invalid request");
            return null;
        }

        // To custom response you can use Results
        if (request.Date.Year == 2024)
            return ResultIn(Results.Ok($"Congratulations! {result}"));

        // Or standard response defined in IPresenter
        if (request.Category >= 10)
            return ResultIn(_presenter.Success($"{result}. Account: {request.Account}. Category: {request.Category}"));

        // By default you need return the TResponse
        return new SampleResponse(result);
    }

    private async Task<string> SomeMethod(SampleRequest request, CancellationToken cancellationToken = default)
    {
        // Some logic
    }
}

Then add your endpoint using minimal api or controller.

app.MapPost("/api/sample", async ([FromBody] SampleRequest request,
    IHandler<SampleRequest> handler,
    CancellationToken cancellationToken) => await handler.HandleAsync(request, cancellationToken));

Finally register your dependencies

builder.Services
    .AddDotEmilu()
    .AddScoped<IHandler<SampleRequest>, SampleUseCase>()
    .AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());

For a complete example

Notes:

You need to add the response messages for bad request (400) and server error (500)

{
  "ResultMessage": {
    "ValidationError": {
      "Title": "Bad Request",
      "Detail": "One or more errors"
    },
    "ServerError": {
      "Title": "Server Error",
      "Detail": "Please contact to administrator"
    }
  }
}

And for complex validation use fluent validation

public class SampleValidator : AbstractValidator<SampleRequest>
{
    public SampleValidator()
    {
        RuleFor(s => s.Date)
            .GreaterThanOrEqualTo(DateOnly.FromDateTime(DateTime.Now));

        RuleFor(s => s.Amount)
            .GreaterThan(0);
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DotEmilu:

Package Downloads
DotEmilu.AspNetCore

Simple .NET library to handle http requests in AspNetCore

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 194 3/31/2025
2.0.0 124 3/28/2025
1.0.3 133 2/18/2025
1.0.2 129 2/18/2025
1.0.1 122 2/4/2025
1.0.0 109 1/13/2025

Initial release of the HTTP request handling library. Easy-to-use API for handling HTTP requests and responses