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
2 changes: 1 addition & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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...)
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion NotoriousClient.Sample/NotoriousClient.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
11 changes: 8 additions & 3 deletions NotoriousClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions NotoriousClient/NotoriousClient.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Description>A fluent HTTPResponseMessage builder with fully extendable API Client implementation.</Description>
<PackageId>NotoriousClient</PackageId>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2.0.0</Version>
<VersionPrefix>2.0.1</VersionPrefix>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Brice SCHUMACHER</Authors>
<RepositoryUrl>https://github.com/Notorious-Coding/Notorious-Client/</RepositoryUrl>
Expand Down
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -128,10 +128,9 @@ services.AddScoped<IRequestSender>((serviceProvider) => new RequestSender(servic
services.AddScoped((serviceProvider) => new UserClient(serviceProvider.GetRequiredService<IRequestSender>(), "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.

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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
{
Expand All @@ -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()

Expand All @@ -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
Expand All @@ -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")

Expand All @@ -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"));
```
Expand All @@ -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()

Expand All @@ -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
Expand All @@ -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")

Expand All @@ -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.

Expand All @@ -321,9 +333,9 @@ public class BearerAuthClient : BaseClient

protected override async Task<IRequestBuilder> 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);
}
Expand Down Expand Up @@ -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 !
Expand Down
Loading