OnlineStore-OrderService-Client
1.0.5
dotnet add package OnlineStore-OrderService-Client --version 1.0.5
NuGet\Install-Package OnlineStore-OrderService-Client -Version 1.0.5
<PackageReference Include="OnlineStore-OrderService-Client" Version="1.0.5" />
<PackageVersion Include="OnlineStore-OrderService-Client" Version="1.0.5" />
<PackageReference Include="OnlineStore-OrderService-Client" />
paket add OnlineStore-OrderService-Client --version 1.0.5
#r "nuget: OnlineStore-OrderService-Client, 1.0.5"
#:package OnlineStore-OrderService-Client@1.0.5
#addin nuget:?package=OnlineStore-OrderService-Client&version=1.0.5
#tool nuget:?package=OnlineStore-OrderService-Client&version=1.0.5
Order API Client for .NET
The Order API Client is a lightweight .NET client library for securely accessing the api/Order/get-all-orders endpoint. This library uses Client ID, Client Secret, and HMAC signing for secure app-to-app communication.
Features
- Supports HMAC for request integrity.
- Uses Client ID and Client Secret for authentication.
- Lightweight and easy to integrate into .NET projects.
- Built-in support for dependency injection (DI).
Installation
Install the NuGet package:
dotnet add package OrderApiClientEnsure you have the following .NET packages installed:
dotnet add package Microsoft.Extensions.DependencyInjection.Abstractions dotnet add package Microsoft.Extensions.Http
Configuration
You need to configure the client with the following parameters:
- BaseUrl: The base URL of the API.
- ClientId: The client ID for authentication.
- ClientSecret: The client secret for authentication.
- HmacKey: The secret key for signing requests using HMAC.
Usage
1. Register the Client in DI
In your Program.cs or Startup.cs, configure the client:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOrderApiClient(options =>
{
options.BaseUrl = "https://example.com"; // API Base URL
options.ClientId = "your-client-id"; // Client ID
options.ClientSecret = "your-client-secret"; // Client Secret
options.HmacKey = "your-hmac-key"; // HMAC Key
});
var app = builder.Build();
2. Inject and Use the Client
You can inject and use the OrderApiClient in your application:
public class OrderService
{
private readonly OrderApiClient _orderApiClient;
public OrderService(OrderApiClient orderApiClient)
{
_orderApiClient = orderApiClient;
}
public async Task FetchOrdersAsync()
{
var orders = await _orderApiClient.GetAllOrdersAsync();
Console.WriteLine(orders);
}
}
Example: Fetching Orders
Here's a complete example of how to fetch orders using this client:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddOrderApiClient(options =>
{
options.BaseUrl = "https://example.com";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.HmacKey = "your-hmac-key";
});
})
.Build();
using var scope = host.Services.CreateScope();
var client = scope.ServiceProvider.GetRequiredService<OrderApiClient>();
var orders = await client.GetAllOrdersAsync();
Console.WriteLine(orders);
Security Considerations
- Protect Your Secrets: Store the
ClientId,ClientSecret, andHmacKeysecurely using a secret manager (e.g., Azure Key Vault). - Key Rotation: Rotate your secrets periodically to reduce the risk of exposure.
- HTTPS: Always use HTTPS to secure communication with the API.
Development & Contribution
Building the Project
Clone the repository and build the project:
git clone https://github.com/your-repo/order-api-client.git
cd order-api-client
dotnet build
Running Tests
Run unit tests to ensure everything works as expected:
dotnet test
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.