https://github.com/beffyman/aspnetcore.client
On Build client generator for asp.net core projects
https://github.com/beffyman/aspnetcore.client
aspnetcore azure-functions blazor c-sharp dotnet dotnet-core generator httpclient signalr
Last synced: 9 months ago
JSON representation
On Build client generator for asp.net core projects
- Host: GitHub
- URL: https://github.com/beffyman/aspnetcore.client
- Owner: Beffyman
- License: mit
- Created: 2018-06-28T01:31:24.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T03:54:25.000Z (about 4 years ago)
- Last Synced: 2025-09-22T15:30:52.287Z (9 months ago)
- Topics: aspnetcore, azure-functions, blazor, c-sharp, dotnet, dotnet-core, generator, httpclient, signalr
- Language: C#
- Size: 1.27 MB
- Stars: 15
- Watchers: 5
- Forks: 3
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Beffyman.AspNetCore.Client
[](https://dev.azure.com/beffyman/Beffyman.Github/_build/latest?definitionId=7&branchName=master)
---
If you are anything like me, you look at
```c#
using(var client = new HttpClient())
{
var request = await client.GetAsync($"api/mysuperspecialroute/{id}");
//Now to make sure what came back is what is expected, in every case...
}
```
and think the following
- Why not just inject clients?
- services.AddTestWebClients();!
- How can I pool the HttpClient usage?
- HttpClient is injected! Which allows you to control it's lifecycle
- Yuck, hard coded routes, these can lead to issues if my endpoint is still under development.
- Generated On Build! Beffyman.AspNetCore.Client.Generator is a before compile build task that will generate clients inside the project that implements it.
- How do I unit test this without spinning up a full web app?
- Works with Microsoft.AspNetCore.TestHost!
- CancellationTokens are not respected inside the TestServer without some hacks though *(registering a kill of the server)* due to the Token not being checked.
- How do I tell my teammates that an endpoint has headers it requires?
- HeaderParameterAttribute! Which makes a header a parameter inside the generated methods, which may or may not be required.
- IncludeHeaderAttribute! Which defines a constant header value to be included
- How do I tell my teammates that an endpoint has known response types for status codes?
- ProducesResponseType! Generates action parameters that allow custom logic depending on the status code returned, without needing to manually check it.
- What if sometimes I want to intercept requests before they go out?
- IHttpOverride! Which allows for potential cache interception of requests.
- If I own the endpoint's code, why can't I just generate clients from it to make interacting with it as simple as injecting it?
- Introducing Beffyman.AspNetCore.Client.Generator!
[First Time Setup](https://github.com/Beffyman/AspNetCore.Client/wiki/First-Time-Setup)
## Supported Frameworks
- AspNetCore 3.1 HTTP Controllers
- AspNetCore 3.1 SignalR Hubs
- AspNetCore 3.1 Blazor Client Side
- Http Trigger Azure Functions v3
## Beffyman.AspNetCore.Client
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client)
Includes ServiceCollection registration logic, used on the Client
## Beffyman.AspNetCore.Client.Generator
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client.Generator)
On Build generator that will generate a Clients.cs file based on the Properties in the csproj.
## Beffyman.AspNetCore.Server
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Server)
Includes attributes that can affect generation, used on your AspNetCore api app
## Beffyman.AspNetCore.Client.Protobuf
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client.Protobuf)
Contains a protobuf serializer which can override the default json one via the UseProtobufSerlaizer on the ClientConfiguration.
```c#
services.AddTestWebClients(config=>
{
config.UseProtobufSerializer()
.UseProtobufDeserializer()
.WithProtobufBody();
});
```
## Beffyman.AspNetCore.Client.MessagePack
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client.MessagePack)
Contains a MessagePack serializer which can override the default json one via the UseMessagePackSerializer on the ClientConfiguration.
Requires version 1.7.3.7 at the moment due to https://github.com/dotnet/aspnetcore/issues/18074
```c#
services.AddTestWebClients(config=>
{
config.UseMessagePackSerializer()
.UseMessagePackDeserializer()
.WithMessagePackBody();
});
```
## Beffyman.AspNetCore.Client.NewtonsoftJson
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client.NewtonsoftJson)
Contains a Newtonsoft Json serializer which can override the default json one via the UseNewtonsoftJsonHttpSerializer on the ClientConfiguration.
```c#
services.AddTestWebClients(config=>
{
config.UseNewtonsoftJsonHttpSerializer()
.UseNewtonsoftJsonHttpDeserializer()
.WithJsonBody();
});
```
## Beffyman.AspNetCore.Client.Http
[](https://www.nuget.org/packages/Beffyman.AspNetCore.Client.Http)
Uses Microsoft.Extensions.Http to inject a client factory. This allows for better reuse of the underlying HttpMessageHandler.
```c#
services.AddTestWebClients(config=>
{
config.UseHttpClientFactory();
});
```