What does this skill do?

La Patrones Ktor para APIs Skill genera esqueletos completos de servidores HTTP con Ktor aplicando patrones probados: estructura de proyecto, routing DSL, autenticación JWT, inyección de dependencias con Koin, serialización kotlinx y testing con testApplication. Produce código listo para ejecutar con respuestas uniformes ApiResponse, manejo centralizado de errores en StatusPages y tests que cubren rutas públicas, protegidas y WebSockets.

REST API from Scratch
Create a complete Ktor server with the following plugins installed in order: serialization, authentication, errors, CORS, DI, and routing.
Plugin Settings
Configure Auth, CORS, Content Negotiation, and Status Pages with centralized exception handling and consistent HTTP status codes.
Injection with Koin
Integrate Koin into your Ktor project to inject services and repositories in a clean way using configurable modules.
Integration Tests
Use `testApplication` to write tests that validate public routes, JWT-protected endpoints, and WebSockets without launching an actual server.

Usage examples

🚀 Full API
Crea un servidor Ktor con rutas de usuarios, autenticación JWT y serialización JSON usando ApiResponse<T>.
💉 Set up Koin
Configure Koin in my Ktor project to inject UserService and UserRepository into the handlers.
🧪 Integration Test
Write a test using `testApplication` for the GET /users endpoint that validates the HTTP status and the JSON body.
💬 WebSocket chat
Implement a WebSocket chat in Ktor with message broadcasting and connection management.

Features

Domain-Based DSL Routing Organize routes into Route extension functions by domain (userRoutes(), authRoutes()) with lightweight handlers.
JWT Authentication Protect sensitive routes with `authenticate("jwt")` and retrieve the user using the `ApplicationCall.userId()` extension.
Dependency Injection with Koin Inyecta servicios con val service by inject<Service>() desde módulos Koin definidos en AppModule.kt.
Respuestas uniformes ApiResponse<T> Model requests and responses using @Serializable and a generic wrapper { success, data, error } for complete consistency.
Integrated testing with testApplication Generates tests that validate HTTP status, JSON body, and JWT authentication without running an actual server.

Frequently asked questions

The skill generates the code and project structure, but you need to have a Kotlin project set up with the Ktor dependencies in your build.gradle.kts file.
Configure ContentNegotiation for KotlinX serialization, Authentication for JWT, StatusPages for error handling, CORS, and Koin for dependency injection.
Yes. The skill generates WebSocket patterns with settings for pingPeriod, maxFrameSize, and connection management with message broadcasting.
Yes. The generated code is a starting point that you can adapt. The patterns follow Ktor conventions but are fully customizable.
Ktor Templates for APIs — Robust HTTP Servers with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.