api-response-patterns
БесплатноБез исполняемых скриптовНе проверенAPI response wrapper patterns for consistent, predictable REST APIs in ABP Framework. Use when: (1) designing uniform API response contracts, (2) implementing…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
API Response Patterns
Master API response wrapper patterns for building consistent, predictable REST APIs that clients love.
When to Use This Skill
- Designing uniform API response contracts
- Implementing success/error response wrappers
- Standardizing error response formats
- Adding metadata to API responses (pagination, timing, version)
- Building APIs consumed by multiple client types (web, mobile, third-party)
Why Response Wrappers?
| Benefit | Description |
|---|---|
| Consistency | All endpoints return same structure |
| Predictability | Clients know what to expect |
| Metadata | Include timing, pagination, version info |
| Error Handling | Uniform error format across all endpoints |
| Debugging | Include correlation IDs for tracing |
Response Wrapper Patterns
1. Basic ResponseModel
// Application.Contracts/Models/ResponseModel.cs
public class ResponseModel<T>
{
public bool IsSuccess { get; set; }
public T Data { get; set; }
public string Message { get; set; }
public List<string> Errors { get; set; } = new();
protected ResponseModel() { }
protected ResponseModel(bool isSuccess, T data, string message, List<string> errors)
{
IsSuccess = isSuccess;
Data = data;
Message = message;
Errors = errors ?? new List<string>();
}
public static ResponseModel<T> Success(T data, string message = null)
=> new(true, data, message, null);
public static ResponseModel<T> Failure(string message)
=> new(false, default, message, new List<string> { message });
public static ResponseModel<T> Failure(List<string> errors)
=> new(false, default, errors.FirstOrDefault(), errors);
}
// Non-generic version for operations without return data
public class ResponseModel : ResponseModel<object>
{
public static ResponseModel Success(string message = null)
=> new() { IsSuccess = true, Message = message };
public new static ResponseModel Failure(string message)
=> new() { IsSuccess = false, Message = message, Errors = new List<string> { message } };
}
2. Extended ApiResponse with Metadata
// Application.Contracts/Models/ApiResponse.cs
public class ApiResponse<T>
{
public bool Success { get; set; }
public T Data { get; set; }
public string Message { get; set; }
public ApiResponseMeta Meta { get; set; }
public List<ApiError> Errors { get; set; } = new();
public static ApiResponse<T> Ok(T data, string message = null) => new()
{
Success = true,
Data = data,
Message = message,
Meta = new ApiResponseMeta()
};
public static ApiResponse<T> Fail(string message, string code = null) => new()
{
Success = false,
Message = message,
Errors = new List<ApiError>
{
new ApiError { Code = code ?? "ERROR", Message = message }
},
Meta = new ApiResponseMeta()
};
public static ApiResponse<T> Fail(List<ApiError> errors) => new()
{
Success = false,
Message = errors.FirstOrDefault()?.Message,
Errors = errors,
Meta = new ApiResponseMeta()
};
}
public class ApiResponseMeta
{
public string Version { get; set; } = "1.0";
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public string RequestId { get; set; } = Guid.NewGuid().ToString("N")[..8];
public long? ProcessingTimeMs { get; set; }
}
public class ApiError
{
public string Code { get; set; }
public string Message { get; set; }
public string Field { get; set; }
public object Details { get; set; }
}
3. Paginated Response
// Application.Contracts/Models/PagedApiResponse.cs
public class PagedApiResponse<T> : ApiResponse<List<T>>
{
public PaginationInfo Pagination { get; set; }
public static PagedApiResponse<T> Ok(
List<T> items,
long totalCount,
int pageNumber,
int pageSize,
string message = null) => new()
{
Success = true,
Data = items,
Message = message,
Meta = new ApiResponseMeta(),
Pagination = new PaginationInfo
{
TotalCount = totalCount,
PageNumber = pageNumber,
PageSize = pageSize,
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
HasPreviousPage = pageNumber > 1,
HasNextPage = pageNumber * pageSize < totalCount
}
};
}
public class PaginationInfo
{
public long TotalCount { get; set; }
public int PageNumber { get; set; }
public int PageSize { get; set; }
public int TotalPages { get; set; }
public bool HasPreviousPage { get; set; }
public bool HasNextPage { get; set; }
}
Usage in AppServices
1. Basic CRUD Operations
public class ProductAppService : ApplicationService, IProductAppService
{
private readonly IRepo
Установить api-response-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл api-response-patterns?
API response wrapper patterns for consistent, predictable REST APIs in ABP Framework. Use when: (1) designing uniform API response contracts, (2) implementing success/error response wrappers, (3) handling pagination and metadata, (4) standardizing error responses.
Как установить скилл api-response-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл api-response-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic