diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index cc3d8ee..f5d8773 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -15,7 +15,7 @@ jobs: publish: env: CONFIGURATION: 'Release' - DOTNET_VERSION: '9.0' + DOTNET_VERSION: '8.0' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b89179c..9f43874 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: publish: env: CONFIGURATION: 'Release' - DOTNET_VERSION: '9.0' + DOTNET_VERSION: '8.0' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2752e91 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +## 2.0.0 + +### 🛠 Technical + +- Upgrade to .NET 8 +- Switch to System.Text.Json to improve performance. + + +## 2.0.1 + +### 🛠 Technical + +- Minor bug fixes on tools (CI, csproj, etc...) \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index d84f5e8..42e2603 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 BRICE SCHUMACHER +Copyright (c) 2025 BRICE SCHUMACHER Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal diff --git a/NotoriousClient.Sample/NotoriousClient.Sample.csproj b/NotoriousClient.Sample/NotoriousClient.Sample.csproj index eec75d0..c731d16 100644 --- a/NotoriousClient.Sample/NotoriousClient.Sample.csproj +++ b/NotoriousClient.Sample/NotoriousClient.Sample.csproj @@ -2,9 +2,10 @@ Exe - net9.0 + net8.0 enable enable + false diff --git a/NotoriousClient.Tests.Unit/NotoriousClient.Tests.Unit.csproj b/NotoriousClient.Tests.Unit/NotoriousClient.Tests.Unit.csproj index 3902634..0edcdc9 100644 --- a/NotoriousClient.Tests.Unit/NotoriousClient.Tests.Unit.csproj +++ b/NotoriousClient.Tests.Unit/NotoriousClient.Tests.Unit.csproj @@ -1,7 +1,7 @@  - net9.0 + net8.0 enable enable diff --git a/NotoriousClient.sln b/NotoriousClient.sln index e8bc920..feadff6 100644 --- a/NotoriousClient.sln +++ b/NotoriousClient.sln @@ -9,14 +9,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotoriousClient.Sample", "N EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NotoriousClient.Tests.Unit", "NotoriousClient.Tests.Unit\NotoriousClient.Tests.Unit.csproj", "{8F832E05-5A6C-4289-AB1E-2CD644E521DF}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Deployment", "Deployment", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Éléments de solution", "Éléments de solution", "{9C8CB701-102D-CF49-A3E0-89AC09D42C2C}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" ProjectSection(SolutionItems) = preProject .github\workflows\prerelease.yml = .github\workflows\prerelease.yml .github\workflows\release.yml = .github\workflows\release.yml EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{152A5ABF-D4EA-4E4E-B0C8-86791981137B}" + ProjectSection(SolutionItems) = preProject + CHANGELOG.md = CHANGELOG.md + LICENSE.txt = LICENSE.txt + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/NotoriousClient/NotoriousClient.csproj b/NotoriousClient/NotoriousClient.csproj index 12dc05c..7ef9fad 100644 --- a/NotoriousClient/NotoriousClient.csproj +++ b/NotoriousClient/NotoriousClient.csproj @@ -1,12 +1,11 @@  - - net9.0 + net8.0 A fluent HTTPResponseMessage builder with fully extendable API Client implementation. NotoriousClient enable enable - 2.0.0 + 2.0.1 README.md Brice SCHUMACHER https://github.com/Notorious-Coding/Notorious-Client/ diff --git a/README.md b/README.md index a48ff4b..fc7d81e 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,15 @@ - [How could i implement a custom BaseClient](#how-could-i-implement-a-custom-baseclient) - [How could i use requestBuilder in Standalone ?](#how-can-i-use-the-requests-builder-in-standalone) - ## Support -- Net6/7 +- .NET 8+ ## Features - Easy building of HttpRequestMessage - Easy building of multipart/form-data requests -- Body serialisation as JSON, powered by Newtonsoft, but customisable. +- Body serialisation as JSON, powered by System.Text.Json, but customisable. - Easy handling of request's authentication - Infinitely extensible system. - Allow you to build maintanable and testable API Client. @@ -39,12 +38,13 @@ First, [install NuGet](http://docs.nuget.org/docs/start-here/installing-nuget). ``` PM> Install-Package NotoriousClient ``` + Or from the .NET CLI as: + ``` dotnet add package NotoriousClient ``` - Then create a client, and inherit from BaseClient : ```csharp @@ -128,10 +128,9 @@ services.AddScoped((serviceProvider) => new RequestSender(servic services.AddScoped((serviceProvider) => new UserClient(serviceProvider.GetRequiredService(), "http://my.api.com/")); ``` +## How could i use RequestBuilder ? -## How could i use RequestBuilder ? - -Lets dive into the possibity of the RequestBuilder ! +Lets dive into the possibity of the RequestBuilder ! ### Configure URN, URL, and http verb. @@ -142,6 +141,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get); ### Configure URI parameters **Add URL parameters** + ```csharp new RequestBuilder("https://toto.com", "/users/{id}", Method.Get).AddEndpointParameter("id", "myfakeid"); @@ -167,6 +167,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).AddQueryParameters( ### Configure request's headers **Add custom headers** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).AddCustomHeader("id", "myfakeid"); @@ -178,6 +179,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).AddCustomHeaders(he ``` **Add accept header** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).WithCustomAcceptMediaType("application/json"); @@ -186,18 +188,21 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithCustomAcceptMed ### Authentication **Add basic authentication** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).WithAuthentication("login", "password"); ``` **Add bearer authentication** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).WithAuthentication("token"); ``` **Add custom scheme authentication** + ```csharp public class NotoriousAuthentication : IAuthenticationInformation { @@ -220,6 +225,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithAuthentication( ### Add body to classic request **Add body as JSON** + ```csharp User user = GetUsersFromDb() @@ -228,6 +234,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithJsonBody(user); ``` **Add body as JSON with a custom serializer** + ```csharp public class CustomSerializer : IJsonSerializer @@ -245,6 +252,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithJsonBody(user, ``` **Add body as Stream** + ```csharp Stream stream = GetFileStream("C:/Crown/BIG.png") @@ -253,6 +261,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithStreamBody(stre ``` **Add body as HTTP Content** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).WithContentBody(new StringContent("MyCustomContent")); ``` @@ -263,8 +272,8 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithContentBody(new > :warning: Note that you CAN'T use multipart bodies if you already added a classic body to the request - **Add body as JSON** + ```csharp User user = GetUsersFromDb() @@ -273,6 +282,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithJsonMultipartBo ``` **Add body as JSON with a custom serializer** + ```csharp public class CustomSerializer : IJsonSerializer @@ -290,6 +300,7 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithJsonMultipartBo ``` **Add body as Stream** + ```csharp Stream stream = GetFileStream("C:/Crown/BIG.png") @@ -298,13 +309,14 @@ new RequestBuilder("https://toto.com", "/users", Method.Get).WithStreamMultipart ``` **Add body as HTTP Content** + ```csharp new RequestBuilder("https://toto.com", "/users", Method.Get).WithContentMultipartBody(new StringContent("MyCustomContent"), "CUSTOM_CONTENT_SECTION"); ``` ## How could i implement a custom BaseClient ? -**NotoriousClient** is entirely designed to be infinitely extensible. +**NotoriousClient** is entirely designed to be infinitely extensible. Let's say you need to get a token from an API before every request. @@ -321,9 +333,9 @@ public class BearerAuthClient : BaseClient protected override async Task GetBuilderAsync(string route, Method method = Method.Get) { - // Get your token every time you create a request. + // Get your token every time you create a request. string token = await GetToken(); - + // Return a preconfigured builder with your token ! return (await base.GetBuilderAsync(route, method)).WithAuthentication(token); } @@ -356,11 +368,13 @@ public class UserClient : BearerAuthClient } } ``` + This is your turn to play with it, you could image everything you want, adding custom authentication, custom company headers, logging ! -## How can i use the request's builder in standalone ? +## How can i use the request's builder in standalone ? You can create a standalone builder by instantiating RequestBuilder. + ```csharp // Dont forget to use IRequestBuilder to have access to extensions method !