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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OnlineStore-OrderService-Client" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OnlineStore-OrderService-Client" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="OnlineStore-OrderService-Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OnlineStore-OrderService-Client --version 1.0.5
                    
#r "nuget: OnlineStore-OrderService-Client, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OnlineStore-OrderService-Client@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OnlineStore-OrderService-Client&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=OnlineStore-OrderService-Client&version=1.0.5
                    
Install as a Cake Tool

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

  1. Install the NuGet package:

    dotnet add package OrderApiClient
    
  2. Ensure 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

  1. Protect Your Secrets: Store the ClientId, ClientSecret, and HmacKey securely using a secret manager (e.g., Azure Key Vault).
  2. Key Rotation: Rotate your secrets periodically to reduce the risk of exposure.
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 189 12/3/2024
1.0.4 171 12/2/2024
1.0.3 155 12/1/2024
1.0.2 162 11/17/2024
1.0.1 158 11/16/2024
1.0.0 148 11/16/2024