api-conventions_skill

This skill enforces MX Space API design conventions for controllers, authentication, responses, pagination, and errors to improve consistency and reliability.
  • TypeScript

481

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill mx-space/core --skill api-conventions

  • SKILL.md2.8 KB

Overview

This skill codifies MX Space API design conventions for writing controllers, endpoints, and HTTP handlers in NestJS/TypeScript. It provides clear, opinionated patterns for routing, authentication, response shape, pagination, validation, error handling, idempotency, and caching. Apply it to keep APIs consistent, predictable, and production-ready.

How this skill works

The skill enforces decorator-based patterns: use @ApiController for routing with automatic versioned prefixes, @Auth and @IsAuthenticated for auth semantics, and Response/JSON interceptors to normalize output and snake_case fields. It standardizes pagination via an explicit Paginator decorator and requires specific return types for automatic pagination formatting. Error handling uses BusinessException and HTTP exceptions to map domain and transport errors cleanly.

When to use it

  • When creating or refactoring NestJS controllers for MX Space services
  • When you need consistent response shapes and snake_case JSON across APIs
  • When implementing auth-sensitive endpoints with optional or required user context
  • When adding paginated list endpoints that must return mongoose.PaginateResult
  • When protecting create operations with idempotency or adding HTTP caching

Best practices

  • Always use @ApiController instead of @Controller so environment prefixes are applied
  • Mark protected endpoints with @Auth() and accept @CurrentUser() where user context is needed
  • Return mongoose.PaginateResult for endpoints using @HTTPDecorators.Paginator to ensure correct pagination format
  • Throw BusinessException for domain errors and standard Nest HTTP exceptions for transport-level errors
  • Apply @HTTPDecorators.Idempotence() on create endpoints and use custom keys for non-standard deduplication
  • Use @HttpCache or @HttpCache.disable explicitly to control caching behavior per endpoint

Example use cases

  • Implementing a posts controller: @ApiController('posts'), create() guarded by @Auth(), list() using @HTTPDecorators.Paginator
  • Building public read endpoints that optionally detect current user via @IsAuthenticated() to tailor response
  • Creating transactional create endpoints with @HTTPDecorators.Idempotence({ key: 'create-post' }) to avoid duplicates
  • Returning 204 for endpoints that yield undefined and 201 for successful resource creation
  • Disabling cache on frequently changing list endpoints with @HttpCache.disable

FAQ

Arrays become { data: [...] }, objects are returned as-is, undefined yields 204 No Content, @Paginator adds pagination metadata, and @Bypass skips transformation.

What status code should I use for create and delete operations?

Use 201 for successful POST creates and 204 for successful DELETE operations with no body.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational