A lightweight .NET Standard 2.1 class library providing reusable data models for web API communication. This library offers essential models for building standardized API responses, handling pagination, managing notifications, and transferring file data.
- ApiResponse - Generic API response wrapper with status, data, message, and notifications support
- Paging - Configurable pagination request model with filter, skip, and take parameters
- PaginationResponse - Generic pagination response model for paginated data
- Notification - Notification model with severity levels and factory methods (Success, Info, Warning, Error)
- FileModel - File transfer model with support for both binary and Base64-encoded content
Install the NuGet package:
dotnet add package ATK.Command.Communication.ModelsOr using the NuGet Package Manager:
Install-Package ATK.Command.Communication.Models
The ApiResponse<T> class provides a standardized API response format with status tracking and notification support:
using ATK.Command.Communication.Models;
// Create a successful response
var response = new ApiResponse<User>
{
Status = "success",
Data = user,
Message = "User retrieved successfully"
};
// Check response status
if (response.IsSuccess)
{
// Handle success
}
// Add notifications
response.Notifications.Add(Notification.Info("Data loaded from cache"));Use the Paging model for pagination requests and PaginationResponse<T> for responses:
// Create a paging request
var paging = new Paging
{
Filter = "active",
Skip = 0,
Take = 20
};
// Create a paginated response
var response = new PaginationResponse<User>
{
Total = 150,
Items = users
};The Notification class provides factory methods for creating different severity levels:
// Create notifications using factory methods
var success = Notification.Success("Operation completed", "Success", new { userId = 123 });
var info = Notification.Info("This is informational", "Info");
var warning = Notification.Warning("Please review this", "Warning");
var error = Notification.Error("An error occurred", "Error");
// Add to response
response.Notifications.AddRange(new[] { success, info });The FileModel class supports both binary and Base64-encoded file content:
var fileModel = new FileModel
{
Name = "document.pdf",
ContentType = "application/pdf",
Content = fileBytes
};
// Convert to Base64 for transmission
fileModel.ToBase64();
// Convert back from Base64
fileModel.FromBase64();Generic API response wrapper for standardized communication.
Properties:
Status- Response status (success, fail, error, forbidden)Data- The response payload of type TMessage- Additional response messageNotifications- List of notification objects
Methods:
IsSuccess- Check if status is "success"IsFail- Check if status is "fail"IsForbidden- Check if status is "forbidden"
Request model for paginating data retrieval.
Properties:
Filter- Search/filter term (default: empty string)Skip- Number of records to skip (default: 0)Take- Number of records to retrieve (default: 10)
Generic response model for paginated data.
Properties:
Total- Total number of items availableItems- Collection of paginated items
Notification object with severity levels.
Properties:
Severity- Severity level (success, info, warning, error)Message- Notification messageTitle- Notification titleVariables- Additional data/context
Factory Methods:
Success(message, title, variables)Info(message, title, variables)Warning(message, title, variables)Error(message, title, variables)
File transfer model supporting binary and Base64 encoding.
Properties:
Content- Binary file content (byte array)Base64EncodedContent- Base64-encoded file contentName- File nameContentType- MIME type
Methods:
ToBase64()- Convert binary content to Base64FromBase64()- Convert Base64 content to binary
- .NET Standard 2.1 or higher
- .NET Framework 4.7.2+
- .NET Core 3.0+
- .NET 5.0+
This project is licensed under the MIT License - see the LICENSE file for details.
GitHub: a-t-k/WebCommunicationModels
0.0.3 - Current stable release