Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ jobs:
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY }}
NUGET_SOURCE_URL: https://api.nuget.org/v3/index.json
run: dotnet nuget push -s ${{ env.NUGET_SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg
PACKAGE_GITHUB_AUTH_TOKEN: ${{ secrets.PACKAGE_GITHUB_API_KEY }}
PACKAGE_GITHUB_SOURCE_URL: https://nuget.pkg.github.com/MyNihongo/index.json
run: |
dotnet nuget push -s ${{ env.NUGET_SOURCE_URL }} -k ${{ env.NUGET_AUTH_TOKEN }} **/*.nupkg
dotnet nuget push -s ${{ env.PACKAGE_GITHUB_SOURCE_URL }} -k ${{ env.PACKAGE_GITHUB_AUTH_TOKEN }} **/*.nupkg
28 changes: 14 additions & 14 deletions MyNihongo.HttpService.sln → MyNihongo.FluentHttp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyNihongo.HttpService", "src\MyNihongo.HttpService.csproj", "{0DDAC867-28E1-488F-AF17-D2952D7CD300}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyNihongo.HttpService.Tests.Integration", "tests\MyNihongo.HttpService.Tests.Integration\MyNihongo.HttpService.Tests.Integration.csproj", "{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyNihongo.FluentHttp", "src\MyNihongo.FluentHttp.csproj", "{0DDAC867-28E1-488F-AF17-D2952D7CD300}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FD657C11-17F5-404A-AD80-4FDD082AE8AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyNihongo.HttpService.Tests.Unit", "tests\MyNihongo.HttpService.Tests.Unit\MyNihongo.HttpService.Tests.Unit.csproj", "{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyNihongo.FluentHttp.Tests.Integration", "tests\MyNihongo.FluentHttp.Tests.Integration\MyNihongo.FluentHttp.Tests.Integration.csproj", "{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyNihongo.FluentHttp.Tests.Unit", "tests\MyNihongo.FluentHttp.Tests.Unit\MyNihongo.FluentHttp.Tests.Unit.csproj", "{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,21 +21,21 @@ Global
{0DDAC867-28E1-488F-AF17-D2952D7CD300}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DDAC867-28E1-488F-AF17-D2952D7CD300}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DDAC867-28E1-488F-AF17-D2952D7CD300}.Release|Any CPU.Build.0 = Release|Any CPU
{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625}.Release|Any CPU.Build.0 = Release|Any CPU
{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB}.Release|Any CPU.Build.0 = Release|Any CPU
{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86}.Release|Any CPU.Build.0 = Release|Any CPU
{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AC82EE62-0AB1-4F45-8853-CC2B6C6B1625} = {FD657C11-17F5-404A-AD80-4FDD082AE8AA}
{A3C21CFE-3FF3-47CB-A844-2ABF88D5EEDB} = {FD657C11-17F5-404A-AD80-4FDD082AE8AA}
{70C004DE-CD00-4B8A-836F-1D6C1F3F4F86} = {FD657C11-17F5-404A-AD80-4FDD082AE8AA}
{BA6228EB-06A5-40FC-AA34-8F4DC423DD6B} = {FD657C11-17F5-404A-AD80-4FDD082AE8AA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {267E0938-5E53-438E-93A6-C7693AA29F9E}
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[![Version](https://img.shields.io/nuget/v/MyNihongo.HttpService?style=plastic)](https://www.nuget.org/packages/MyNihongo.HttpService/)
[![Nuget downloads](https://img.shields.io/nuget/dt/MyNihongo.HttpService?label=nuget%20downloads&logo=nuget&style=plastic)](https://www.nuget.org/packages/MyNihongo.HttpService/)
[![Version](https://img.shields.io/nuget/v/MyNihongo.FluentHttp?style=plastic)](https://www.nuget.org/packages/MyNihongo.FluentHttp/)
[![Nuget downloads](https://img.shields.io/nuget/dt/MyNihongo.FluentHttp?label=nuget%20downloads&logo=nuget&style=plastic)](https://www.nuget.org/packages/MyNihongo.FluentHttp/)

# HttpService
# FluentHttp
Fluent wrapper around IHttpClientFactory
Install a NuGet package `MyNihongo.HttpService`.
Install a NuGet package `MyNihongo.FluentHttp`.

## Configuration
Add a section to `IConfiguration`
```json
{
"HttpClient": {
"FluentHttp": {
"BaseAddress": "https://jsonplaceholder.typicode.com",
"NtlmEnabled": false
}
}
```
Register a service
```cs
using MyNihongo.HttpService;
using MyNihongo.FluentHttp;

services.AddHttpService();
services.AddFluentHttp();
```

## HTTP methods
To optimize JSON serialization `JsonTypeInfo<T>` can be supplied for all methods. More info about these types [here](https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/).
In further examples a variable `IHttpService httpService` will be used.
In further examples a variable `IFluentHttp fluentHttp` will be used.

#### GetJsonAsync
Gets a JSON stream.
Expand All @@ -38,7 +38,7 @@ public sealed record RecordContext
}

// Get the model
var models = await httpService
var models = await fluentHttp
.AppendPathSegment("example")
.GetJsonAsync(RecordContext.Default.RecordArray, ct);
```
Expand All @@ -57,7 +57,7 @@ var req = new Request
Data = "example"
};

var response = await httpService
var response = await fluentHttp
.AppendPathSegment("example")
.PostJsonAsync(req, RequestContext.Default.Request, ResponseContext.Default.Response, ct);
```
Expand All @@ -69,7 +69,7 @@ Fluent extensions supply additional parameters for the main HTTP methods.
Appends a new section to the request URI.
```cs
// get from https://jsonplaceholder.typicode.com/posts
var result = await httpService
var result = await fluentHttp
.AppendPathSegment("posts")
.GetJsonAsync<PostRecord>();
```
Expand All @@ -78,15 +78,15 @@ var result = await httpService
Appends multiple sections to the request URI.
```cs
// get from https://jsonplaceholder.typicode.com/posts/1/comments
var result = await httpService
var result = await fluentHttp
.AppendPathSegment("posts", "1", "comments")
.GetJsonAsync<PostCommentRecord>();
```

#### WithHeader
Appends a header to the request.
```cs
var result = await httpService
var result = await fluentHttp
.AppendPathSegment("posts")
.WithHeader("my-header", "value")
.GetJsonAsync<PostRecord>();
Expand Down
3 changes: 2 additions & 1 deletion src/DefaultHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using System.Text.Json.Serialization.Metadata;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using MyNihongo.FluentHttp;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal sealed class DefaultHttpService : IHttpService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/HttpCallException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public sealed class HttpCallException : Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fluent/Extensions/HttpServiceEx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public static class HttpServiceEx
{
Expand Down
3 changes: 2 additions & 1 deletion src/Fluent/Extensions/HttpServiceWithOptionsEx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json.Serialization.Metadata;
using MyNihongo.FluentHttp;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public static class HttpServiceWithOptionsEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fluent/HttpServiceWithOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal sealed class HttpServiceWithOptions : IHttpServiceWithOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/Fluent/IHttpServiceWithOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public interface IHttpServiceWithOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/IHttpService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization.Metadata;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public interface IHttpService
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/HttpCallOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public sealed record HttpCallOptions
{
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/Resources/ConfigKeys.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class ConfigKeys
{
public const string Section = "HttpClient",
public const string Section = "FluentHttp",
BaseAddress = "BaseAddress",
UseNtlmAuthentication = "NtlmEnabled";
}
2 changes: 1 addition & 1 deletion src/Resources/Const.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class Const
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/ConfigurationEx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class ConfigurationEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/HttpCallOptionsEx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class HttpCallOptionsEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/ObjectEx.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class ObjectEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/StreamEx.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class StreamEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/StringEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text.Json.Serialization.Metadata;
using Microsoft.Extensions.ObjectPool;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class StringEx
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Extensions/UriEx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

internal static class UriEx
{
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/ServiceRegistration/ServiceCollectionEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MyNihongo.HttpService;
namespace MyNihongo.FluentHttp;

public static class ServiceCollectionEx
{
public static IServiceCollection AddHttpService(this IServiceCollection @this)
public static IServiceCollection AddFluentHttp(this IServiceCollection @this)
{
@this
.AddHttpClient(Const.FactoryName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text.Json;
using ApprovalTests;

namespace MyNihongo.HttpService.Tests.Integration;
namespace MyNihongo.FluentHttp.Tests.Integration;

internal static class ApprovalTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Threading.Tasks;
using MyNihongo.HttpService.Tests.Integration.Models;
using MyNihongo.FluentHttp.Tests.Integration.Models;
using Serilog.Events;
using Xunit;

namespace MyNihongo.HttpService.Tests.Integration.HttpServiceTests;
namespace MyNihongo.FluentHttp.Tests.Integration.HttpServiceTests;

public sealed class GetJsonAsyncShould : HttpServiceTestsBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Serilog.Core;
using Serilog.Events;

namespace MyNihongo.HttpService.Tests.Integration.HttpServiceTests;
namespace MyNihongo.FluentHttp.Tests.Integration.HttpServiceTests;

public abstract class HttpServiceTestsBase
{
Expand All @@ -28,7 +28,7 @@ protected HttpServiceTestsBase()
_serviceProvider = new ServiceCollection()
.AddLogging(x => x.AddSerilog(serilogLogger))
.AddSingleton<IConfiguration>(configuration)
.AddHttpService()
.AddFluentHttp()
.BuildServiceProvider(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Text.Json;
using System.Threading.Tasks;
using MyNihongo.HttpService.Tests.Integration.Models;
using MyNihongo.FluentHttp.Tests.Integration.Models;
using Serilog.Events;
using Xunit;

namespace MyNihongo.HttpService.Tests.Integration.HttpServiceTests;
namespace MyNihongo.FluentHttp.Tests.Integration.HttpServiceTests;

public sealed class PostJsonAsyncShould : HttpServiceTestsBase
{
Expand Down Expand Up @@ -35,7 +35,7 @@ public async Task PostDataWithVerboseLogging()
}

[Fact]
public async Task PostDaaWithoutVerboseLogging()
public async Task PostDataWithoutVerboseLogging()
{
LogLevel = LogEventLevel.Information;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MyNihongo.HttpService.Tests.Integration.Models;
namespace MyNihongo.FluentHttp.Tests.Integration.Models;

[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(PostRecord[]))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MyNihongo.HttpService.Tests.Integration.Models;
namespace MyNihongo.FluentHttp.Tests.Integration.Models;

[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(UserRecord[]))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MyNihongo.HttpService.csproj" />
<ProjectReference Include="..\..\src\MyNihongo.FluentHttp.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"HttpClient": {
"FluentHttp": {
"BaseAddress": "https://jsonplaceholder.typicode.com"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Xunit;

namespace MyNihongo.HttpService.Tests.Unit.HttpServiceTests;
namespace MyNihongo.FluentHttp.Tests.Unit.HttpServiceTests;

public sealed class AppendPathSegmentShould : HttpServiceTestsBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Xunit;

namespace MyNihongo.HttpService.Tests.Unit.HttpServiceTests;
namespace MyNihongo.FluentHttp.Tests.Unit.HttpServiceTests;

public sealed class AppendPathSegmentsShould : HttpServiceTestsBase
{
Expand Down
Loading