Skip to content

Added .NET REST template#28

Merged
harveymmaunders merged 7 commits intomainfrom
dotnet-rest-template
Jun 9, 2025
Merged

Added .NET REST template#28
harveymmaunders merged 7 commits intomainfrom
dotnet-rest-template

Conversation

@harveymmaunders
Copy link
Owner

No description provided.

@harveymmaunders harveymmaunders force-pushed the dotnet-rest-template branch 2 times, most recently from cb5e7ac to bb79a0a Compare May 2, 2025 15:02
@harveymmaunders harveymmaunders force-pushed the dotnet-rest-template branch 4 times, most recently from 509a2c9 to bda9660 Compare May 14, 2025 15:44
Copy link

@willosborne willosborne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will defer to @mgasca for final approval before merge but this seems easy to use and comments/docs are good.

@ZKRobi
Copy link

ZKRobi commented May 15, 2025

A lot of the naming conventions seem very web-like to me e.g. in the service names or the project names.
In C# different different casing is used. It's a bit nitpicky but since this is a template for C# developers I'd consider reviewing the naming style to match the style C# developers are familiar with:
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/identifier-names

@harveymmaunders
Copy link
Owner Author

@ZKRobi this is useful feedback thank you. Will look into these now

Copy link

@mgasca mgasca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to have the 3 nitpick open comments under single review addressed later or not at all, approving PR

httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

// Make a GET request
return httpClient.GetAsync(url).Result;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose following through with keeping calls async.
So rather than calling .Result, the method could be "public static async Task GetResponseAsync" and then await the call.
CallApi would then be "public static Task CallApi" and await GetResponse.

using (X509Certificate2 certificate = GetCertificate(_clientCredentialSettings.PublicKeyFile, _clientCredentialSettings.PrivateKeyFile))
{
var app = CreateConfidentialClient(_clientCredentialSettings.ClientId, GetAuthority(_clientCredentialSettings.Tenant), certificate);
token = GetToken(app).Result;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose to be consistent with using async everywhere - same as in the ApiService, GetAuthToken could return Task and await here.

var authTokenService = new AuthTokenService(settings);

// Retrieve the authentication token synchronously
var token = authTokenService.GetAuthToken();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to the ApiService and ConfigService comments, if those are made async, here, they would be awaited, and the whole thing would work the same. An implicit main method is async by default, no need to change anything else.

@harveymmaunders harveymmaunders merged commit e88180b into main Jun 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants