Skip to content

Latest commit

 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetTailor - Http weaved effortlessly

CI NuGet NuGet

NetTailor simplifies development with a declarative, CQRS-like approach that reduces boilerplate code and streamlines maintenance, allowing you to focus on the data-in and data-out.

Installing NetTailor

With .NET CLI:

dotnet add package NetTailor

Using NetTailor

Or use example code

1. Create your profile

// use against IServiceCollection
var clientBuilder = services.AddHttpClientProfile("example", client =>
{
    client.BaseAddress = new Uri("http://api.example.com/");
});

2. Create a request by chaining it with IHttpClientBuilder

clientBuilder.Get<SampleGet, SampleGetResponse>(r => $"users/{r.Id}/friends", // configure route 
            reqBuilder => // configure request
            {
                reqBuilder.Headers((_, h) => h.Add("PER-REQUEST-HEADER", "some-value"));
                reqBuilder.Query(q => new { Sort = "Asc", OrderBy = nameof(q.Name) });
            });

- 3 Use it, by injecting IRequestDispatcher into your services

var request = new SampleGet { Id = 1, Name = "John" };
var dispatcher = serviceProvider.GetService<IRequestDispatcher>();
var response = await dispatcher.Dispatch<SampleGet, SampleGetResponse>(request, CancellationToken.None);

4.1. Sending JSON

clientBuilder.Post<SamplePost, SamplePostResponse>("users",
            reqBuilder => 
            {
                reqBuilder.Content(r => new 
                {
                    r.Email,
                    r.Name,
                    r.Password,
                    r.PasswordConfirmation,
                });
            });

4.2. Sending files

clientBuilder.Post<SampleUpload, SampleUploadResult>(r => $"users/{r.Id}/photos"
            reqBuilder => 
            {
                reqBuilder.Form(r => new 
                {
                    Photo = r.File, // a stream, will be translated to form-data
                    r.Description,
                    r.IsPublic,
                });
            });

About

Weave your web requests with a bit of tailor's touch

Topics

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages