Claude-skill-registry api-endpoint-pattern
Standards for creating and organizing HTTP API endpoints using the Echo framework
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/api-endpoint-pattern" ~/.claude/skills/majiayu000-claude-skill-registry-api-endpoint-pattern && rm -rf "$T"
manifest:
skills/data/api-endpoint-pattern/SKILL.mdsource content
API Endpoint Pattern Skill
Use this skill when adding or modifying HTTP endpoints in the API.
Scope
- Creating new API endpoints
- Adding new domain routers
- Modifying handler logic
Router Structure
Main Router (internal/router/router.go
)
internal/router/router.goInitializes Echo, sets up middleware, and groups routes by domain.
Sub-Routers (internal/router/[domain]/router.go
)
internal/router/[domain]/router.goEach domain has its own sub-router with a
Bind function that receives an *echo.Group and dependencies.
func Bind(e *echo.Group, db *sql.DB) *echo.Group { e.GET("/list", func(c echo.Context) error { // handler logic }) return e }
Adding a New Endpoint
- If introducing a new domain, create
.internal/router/[domain]/router.go - Implement a
function.Bind(e *echo.Group, db *sql.DB) *echo.Group - Register the sub-router in
:internal/router/router.godomainrouter.Bind(api.Group("/domain"), config.DB.Conn) - Implement data access logic in
if needed.internal/models/
Handler Guidelines
- Parameter Parsing: Use helper functions for complex query params (e.g., trader levels).
- Dependency Injection: Pass
into*sql.DB
, then into handlers. Avoid globals.Bind - Response Handling:
- Success:
orc.JSON(200, data)c.String(200, "OK") - Error:
— log significant errors with zerolog.c.String(code, err.Error())
- Success:
- Business Logic: Keep handlers thin. Move complex logic to
or other internal packages.internal/models/
Conventions
- Use
for logical route separation.e.Group() - Use plural names for collections (
,/items
)./weapons - Use query parameters for filtering and optional configuration.
- Prefer HTTP status constants for consistency, but be consistent either way.