![]() |
VOOZH | about |
dotnet add package CG.Infrastructure.Responses --version 3.10.11
NuGet\Install-Package CG.Infrastructure.Responses -Version 3.10.11
<PackageReference Include="CG.Infrastructure.Responses" Version="3.10.11" />
<PackageVersion Include="CG.Infrastructure.Responses" Version="3.10.11" />Directory.Packages.props
<PackageReference Include="CG.Infrastructure.Responses" />Project file
paket add CG.Infrastructure.Responses --version 3.10.11
#r "nuget: CG.Infrastructure.Responses, 3.10.11"
#:package CG.Infrastructure.Responses@3.10.11
#addin nuget:?package=CG.Infrastructure.Responses&version=3.10.11Install as a Cake Addin
#tool nuget:?package=CG.Infrastructure.Responses&version=3.10.11Install as a Cake Tool
A .NET 10.0 library that provides comprehensive HTTP response handling services for web API interactions, including authentication, entity management, and response processing.
This library offers a robust set of response services designed to handle various HTTP operations in .NET applications. It provides both basic HTTP response handling and advanced features like authentication token management, entity CRUD operations, and response serialization.
The custom header functionality integrates with CG.Infrastructure.Http:
appsettings.jsonRegisterInfraHttpServicespublic interface IResponseService : IService
{
// HTTP Response Operations
Task<HttpResponseMessage?> GetWebResponse(string? requestUri);
Task<HttpResponseMessage?> GetWebResponseWithCustomHeaders(string? requestUri);
Task<string> GetResponseAsString(HttpResponseMessage response);
Task<string[]> GetResponseAsStringArray(HttpResponseMessage response);
// Entity CRUD Operations
Task<TEntity?> GetEntity<TEntity>(string? requestUri, string? baseUrl, TokenResponse? token);
Task<TEntity?> GetEntityFromPost<TEntity>(string? requestUri, TEntity? entity, string? baseUrl, TokenResponse? token);
Task<TEntity?> GetEntityFromPut<TEntity>(string? requestUri, TEntity? entity, string? baseUrl, TokenResponse? token);
Task DeleteEntity(string? requestUri, Guid? id, string? baseUrl, TokenResponse? token);
// Authentication Operations
Task<TokenResponse?> GetClientCredentialsToken(string clientId, string? clientSecret, string? clientScope);
Task<TokenResponse?> GetClientPasswordToken(string clientId, string? clientSecret, string? clientScope, string userName, SecureString password);
Task<UserInfoResponse?> GetUserInfoRequest(TokenResponse token);
bool IsTokenExpired(TokenResponse? token);
Task<TokenResponse?> GetValidTokenAsync(string clientId, string? clientSecret, string? clientScope, TokenResponse? currentToken);
}
var responseService = serviceProvider.GetService<IResponseService>();
// Get web response
var response = await responseService.GetWebResponse("https://api.example.com/data");
// Get web response with custom headers (API keys, custom Accept, etc.)
var authenticatedResponse = await responseService.GetWebResponseWithCustomHeaders("https://api.example.com/secure");
// Extract content as string
var content = await responseService.GetResponseAsString(response);
// Extract content as string array
var lines = await responseService.GetResponseAsStringArray(response);
var responseService = serviceProvider.GetService<IResponseService>();
// Get entity with authentication
var entity = await responseService.GetEntity<MyEntity>(
"api/entities/123",
"https://api.example.com",
authToken
);
// Create entity via POST
var newEntity = await responseService.GetEntityFromPost<MyEntity>(
"api/entities",
entityData,
"https://api.example.com",
authToken
);
// Get GUID from POST response
var id = await responseService.GetGuidFromPost<MyEntity>(
"api/entities",
entityData,
"https://api.example.com",
authToken
);
var responseService = serviceProvider.GetService<IResponseService>();
// Get client credentials token
var token = await responseService.GetClientCredentialsToken(
"clientId",
"clientSecret",
"api.scope"
);
// Get user info
var userInfo = await responseService.GetUserInfoRequest(token);
// Check if token has expired
if (responseService.IsTokenExpired(token))
{
// Token is expired, get a new one
token = await responseService.GetClientCredentialsToken(
"clientId",
"clientSecret",
"api.scope"
);
}
var responseService = serviceProvider.GetService<IResponseService>();
TokenResponse? cachedToken = null;
// Get valid token (reuses existing if valid, gets new if expired/null)
var token = await responseService.GetValidTokenAsync(
"clientId",
"clientSecret",
"api.scope",
cachedToken
);
// Use token for API calls
var entity = await responseService.GetEntity<MyEntity>(
"api/entities/123",
"https://api.example.com",
token
);
// Update cached token for future use
cachedToken = token;
The GetWebResponseWithCustomHeaders method provides HTTP requests with configurable custom headers:
var responseService = serviceProvider.GetService<IResponseService>();
// Make authenticated request with custom headers
var response = await responseService.GetWebResponseWithCustomHeaders("https://api.example.com/protected");
// Custom headers are automatically applied based on configuration
// Common use cases include:
// - API key authentication (x-api-key, x-gg-bot-access)
// - Custom Accept headers
// - User-Agent specification
// - Custom authentication tokens
Configuration Required:
appsettings.jsonThe library integrates with the .NET dependency injection container and can be configured through standard service registration:
// Register response services
services.RegisterInfraResponseServices(configuration);
// Or register individually
services.AddScoped<IResponseService, ResponseService>();
To use custom headers, configure them in your appsettings.json:
{
"CustomHeaders": {
"Headers": {
"x-gg-bot-access": "{{ENV:GG_BOT_ACCESS_TOKEN}}",
"Accept": "application/json",
"User-Agent": "MyApp/1.0"
}
}
}
Environment Variable Support:
# Set environment variables
export GG_BOT_ACCESS_TOKEN="your-token-here"
# Or in Windows PowerShell
$env:GG_BOT_ACCESS_TOKEN="your-token-here"
The library follows a layered architecture pattern:
This project is part of the CG Infrastructure Libraries and follows the same licensing terms as the parent project.
Please refer to the main project documentation for contribution guidelines and coding standards.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on CG.Infrastructure.Responses:
| Package | Downloads |
|---|---|
|
CG.Platform.ViewModels
Platform view models library with shared services |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.10.11 | 128 | 4/1/2026 |
| 3.10.10 | 238 | 10/15/2025 |
| 3.10.9 | 235 | 10/8/2025 |
| 3.10.8 | 177 | 8/16/2025 |
| 3.10.7 | 213 | 8/15/2025 |
| 3.10.6 | 206 | 8/15/2025 |
| 3.10.5 | 265 | 8/10/2025 |
| 3.10.4 | 269 | 7/2/2025 |
| 3.10.3 | 266 | 6/17/2025 |
| 3.10.2 | 246 | 6/16/2025 |
| 3.10.1 | 400 | 6/12/2025 |
| 3.10.0 | 402 | 6/11/2025 |
| 3.9.0 | 234 | 12/10/2024 |
| 3.0.2 | 272 | 8/13/2024 |
| 3.0.1 | 248 | 8/12/2024 |
| 3.0.0 | 241 | 3/26/2024 |
| 2.0.0 | 351 | 6/2/2023 |
| 1.0.1 | 397 | 5/27/2022 |
| 1.0.0 | 340 | 5/27/2022 |