[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71GR4NBW66HDEV51Y4CW06G":3,"skill-same:01M71GR4NBW66HDEV51Y4CW06G":104},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":25,"publishedAt":46,"linkOnly":47,"markdownContent":48,"markdownBody":49,"frontMatter":50,"refName":53,"commitSha":54,"skillDirectory":55,"forksCount":56,"repositoryHtmlUrl":57,"repositoryHomepageUrl":6,"ownerHtmlUrl":58,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":59,"install":60,"resources":73},"01M71GR4NBW66HDEV51Y4CW06G","backend-endpoint",null,"Create REST\u002FGraphQL API endpoint with validation, error handling, and tests. Auto-invoke when user says \"add endpoint\", \"create API\", \"new route\", or \"add route\".","JSGforever\u002Fskillguard","JSGforever","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F85541948?v=4","01M71FQD3E132VMR5F4TAYX3YS","01M71FQD4DYW0XJ4XQ4YQH75Y9",2,"GPL-3.0","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002FSKILL.md",[17,22],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":23,"categoryName":24,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000010","后端与接口",[26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45],"endpoint","backend","backend endpoint","error handling","tests","api endpoint","add","edit","write","read","auto-invoke","create","route","api","Bash","when","invoke","auto","new","error","2026-11-10 10:12:30",false,"---\nname: backend-endpoint\ndescription: Create REST\u002FGraphQL API endpoint with validation, error handling, and tests. Auto-invoke when user says \"add endpoint\", \"create API\", \"new route\", or \"add route\".\nallowed-tools: Read, Write, Edit, Grep, Glob, Bash\nversion: 1.0.0\n---\n\n# Backend API Endpoint Generator\n\nGenerate production-ready REST or GraphQL endpoints with request validation, error handling, and comprehensive tests.\n\n## When to Invoke\n\nAuto-invoke when user mentions:\n- \"Add endpoint\"\n- \"Create API\"\n- \"New route\"\n- \"Add route\"\n- \"Create API endpoint for [resource]\"\n\n## What This Does\n\n1. Generates route handler with proper HTTP methods\n2. Adds request validation (body, params, query)\n3. Implements error handling\n4. Creates test file with request\u002Fresponse tests\n5. Follows REST\u002FGraphQL conventions\n6. Includes authentication middleware (if needed)\n\n## Execution Steps\n\n### Step 1: Gather Endpoint Requirements\n\n**Ask user for endpoint details**:\n```\nEndpoint path: [e.g., \u002Fapi\u002Fusers\u002F:id]\nHTTP method: [GET, POST, PUT, PATCH, DELETE]\nResource name: [e.g., User, Post, Product]\n\nFramework:\n  - express (default)\n  - fastify\n  - nestjs\n  - graphql\n\nAuthentication required: [yes\u002Fno]\nRequest validation needed: [yes\u002Fno]\n```\n\n**Validate endpoint path**:\n- Use predefined function: `functions\u002Froute_validator.py`\n- Ensure RESTful conventions\n- Check path parameters syntax\n- No trailing slashes\n\n### Step 1.5: Verify Understanding (ToM Checkpoint) [EXECUTE]\n\n**IMPORTANT**: This step MUST be executed for high-stakes operations.\n\n**Before generating code, confirm interpretation with user**.\n\n**Display verification**:\n```\nI understood you want:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nEndpoint: {METHOD} {PATH}\nResource: {RESOURCE_NAME}\nFramework: {FRAMEWORK} (detected from package.json \u002F specified)\nAuth required: {yes\u002Fno}\nValidation needed: {yes\u002Fno}\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nAssumptions I'm making:\n- Using {VALIDATION_LIBRARY} for validation (detected from existing validators)\n- Error handling follows existing pattern in {ERROR_HANDLER_PATH}\n- Route will be registered at {ROUTE_PREFIX} prefix\n\nProceed with generation? [Y\u002Fn]\n```\n\n**Skip verification if** (HIGH-STAKES ONLY mode):\n- Simple CRUD operation (single resource, single path parameter)\n- User explicitly said \"quick\", \"just do it\", or \"skip confirmation\"\n- No custom authentication logic specified\n- Standard GET\u002FPOST\u002FPUT\u002FDELETE without complex business logic\n\n**Always verify if**:\n- Multiple path parameters (e.g., `\u002Fusers\u002F:userId\u002Fposts\u002F:postId`)\n- Custom authorization logic specified\n- Non-standard HTTP methods or patterns\n- GraphQL mutations with side effects\n- Endpoints involving financial or sensitive data\n\n### Step 1.8: Declare Belief State (Optional - ToM Anchor)\n\n**Before generating code, optionally declare explicit assumptions** (enabled by `tom_features.belief_anchors` in config).\n\n**Display belief state anchor**:\n```\n📌 BELIEF STATE\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nWhat I know (from context):\n✅ Framework: {FRAMEWORK} (from package.json)\n✅ TypeScript: {strict\u002Fnormal} mode (from tsconfig.json)\n✅ Validation: {LIBRARY} (from existing validators\u002F)\n\nWhat I'm assuming (inference):\n🔸 Error handler follows pattern in {PATH}\n🔸 Routes registered at {PREFIX} prefix\n🔸 Using {CONVENTION} commit messages\n\nWhat I don't know (using defaults):\n❓ Request logging preference (will include)\n❓ Rate limiting requirements (will skip)\n❓ Response envelope format (will use standard)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nAdjustments needed before I proceed?\n```\n\n**Skip belief anchor if**:\n- `tom_features.belief_anchors` is false in config\n- User said \"skip\", \"just do it\", \"quick\"\n- Simple endpoint with no custom logic\n\n**Show belief anchor if**:\n- Complex endpoint with multiple integrations\n- User profile indicates preference for detailed explanations\n- First endpoint in a new project (establishing patterns)\n\n### Step 2: Generate Route Handler\n\n**Based on HTTP method and framework**:\n\nUse predefined function: `functions\u002Fendpoint_generator.py`\n\n```bash\npython3 functions\u002Fendpoint_generator.py \\\n  --path \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --resource \"User\" \\\n  --framework \"express\" \\\n  --auth true \\\n  --validation true \\\n  --template \"templates\u002Fexpress-route-template.ts\" \\\n  --output \"src\u002Froutes\u002Fusers.ts\"\n```\n\n**Template includes**:\n- Route definition\n- Request validation middleware\n- Controller\u002Fhandler function\n- Error handling\n- Response formatting\n- TypeScript types\n\n### Step 3: Generate Validation Schema\n\n**Use predefined function**: `functions\u002Fvalidation_generator.py`\n\n```bash\npython3 functions\u002Fvalidation_generator.py \\\n  --resource \"User\" \\\n  --method \"POST\" \\\n  --fields \"name:string:required,email:email:required,age:number:optional\" \\\n  --library \"zod\" \\\n  --output \"src\u002Fvalidators\u002Fuser.validator.ts\"\n```\n\n**Supported validation libraries**:\n- Zod (default, TypeScript-first)\n- Joi (JavaScript schema)\n- Yup (object schema)\n- Express-validator (middleware-based)\n\n**Output example (Zod)**:\n```typescript\nimport { z } from 'zod';\n\nexport const createUserSchema = z.object({\n  name: z.string().min(1),\n  email: z.string().email(),\n  age: z.number().optional(),\n});\n\nexport type CreateUserInput = z.infer\u003Ctypeof createUserSchema>;\n```\n\n### Step 4: Generate Error Handling Middleware\n\n**Use predefined function**: `functions\u002Ferror_handler_generator.py`\n\n```bash\npython3 functions\u002Ferror_handler_generator.py \\\n  --framework \"express\" \\\n  --template \"templates\u002Ferror-handler-template.ts\" \\\n  --output \"src\u002Fmiddleware\u002FerrorHandler.ts\"\n```\n\n**Error handler includes**:\n- HTTP status code mapping\n- Error response formatting\n- Logging integration\n- Development vs production modes\n- Validation error handling\n\n### Step 5: Generate Test File\n\n**Use predefined function**: `functions\u002Ftest_generator.py`\n\n```bash\npython3 functions\u002Ftest_generator.py \\\n  --endpoint \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --framework \"express\" \\\n  --template \"templates\u002Fendpoint-test-template.spec.ts\" \\\n  --output \"tests\u002Froutes\u002Fusers.test.ts\"\n```\n\n**Test template includes**:\n- Success case (200\u002F201)\n- Validation errors (400)\n- Not found (404)\n- Unauthorized (401)\n- Server errors (500)\n- Edge cases\n\n**Example test**:\n```typescript\ndescribe('GET \u002Fapi\u002Fusers\u002F:id', () => {\n  it('returns user when found', async () => {\n    const response = await request(app)\n      .get('\u002Fapi\u002Fusers\u002F123')\n      .expect(200);\n\n    expect(response.body).toMatchObject({\n      id: '123',\n      name: expect.any(String),\n    });\n  });\n\n  it('returns 404 when user not found', async () => {\n    await request(app)\n      .get('\u002Fapi\u002Fusers\u002F999')\n      .expect(404);\n  });\n});\n```\n\n### Step 6: Generate API Documentation Comment\n\n**JSDoc or OpenAPI annotation**:\n\n```typescript\n\u002F**\n * @route GET \u002Fapi\u002Fusers\u002F:id\n * @description Get user by ID\n * @access Private\n * @param {string} id - User ID\n * @returns {User} User object\n * @throws {404} User not found\n * @throws {401} Unauthorized\n *\u002F\n```\n\n### Step 7: Show Endpoint Summary\n\n**Display generated files and usage**:\n\n```\n✅ Endpoint Created: GET \u002Fapi\u002Fusers\u002F:id\n\nStructure:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📁 src\u002F\n   ├── routes\u002Fusers.ts                (Route handler)\n   ├── validators\u002Fuser.validator.ts   (Request validation)\n   └── middleware\u002FerrorHandler.ts     (Error handling)\n\n📁 tests\u002F\n   └── routes\u002Fusers.test.ts           (Integration tests)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nRoute Registration:\nimport { userRoutes } from '.\u002Froutes\u002Fusers';\napp.use('\u002Fapi', userRoutes);\n\nTest:\ncurl http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fusers\u002F123\n# or\nnpm test -- users.test.ts\n\nNext Steps:\n1. Implement business logic in controller\n2. Connect to database\u002Fservice layer\n3. Run tests: npm test\n4. Test with Postman\u002FThunder Client\n```\n\n---\n\n## Predefined Functions\n\n### 1. route_validator.py\n\nValidates route path follows REST conventions.\n\n**Usage**:\n```bash\npython3 functions\u002Froute_validator.py --path \"\u002Fapi\u002Fusers\u002F:id\" --method \"GET\"\n```\n\n**Checks**:\n- RESTful naming (plural resources)\n- Path parameter syntax (`:id` or `{id}`)\n- No trailing slashes\n- HTTP method matches intent\n\n**Returns**: Valid path or error message\n\n---\n\n### 2. endpoint_generator.py\n\nGenerates endpoint handler from template.\n\n**Usage**:\n```bash\npython3 functions\u002Fendpoint_generator.py \\\n  --path \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --resource \"User\" \\\n  --framework \"express\" \\\n  --auth true \\\n  --validation true \\\n  --template \"templates\u002Fexpress-route-template.ts\"\n```\n\n**Parameters**:\n- `--path`: API endpoint path\n- `--method`: HTTP method\n- `--resource`: Resource name (singular, PascalCase)\n- `--framework`: Backend framework\n- `--auth`: Include auth middleware\n- `--validation`: Include validation middleware\n- `--template`: Template file path\n\n**Returns**: Generated endpoint code\n\n---\n\n### 3. validation_generator.py\n\nGenerates request validation schema.\n\n**Usage**:\n```bash\npython3 functions\u002Fvalidation_generator.py \\\n  --resource \"User\" \\\n  --method \"POST\" \\\n  --fields \"name:string:required,email:email:required\" \\\n  --library \"zod\"\n```\n\n**Supported field types**:\n- `string`, `number`, `boolean`\n- `email`, `url`, `uuid`\n- `array`, `object`\n- `date`, `datetime`\n\n**Returns**: Validation schema code\n\n---\n\n### 4. error_handler_generator.py\n\nGenerates error handling middleware.\n\n**Usage**:\n```bash\npython3 functions\u002Ferror_handler_generator.py \\\n  --framework \"express\" \\\n  --template \"templates\u002Ferror-handler-template.ts\"\n```\n\n**Returns**: Error handler middleware code\n\n---\n\n### 5. test_generator.py\n\nGenerates endpoint integration tests.\n\n**Usage**:\n```bash\npython3 functions\u002Ftest_generator.py \\\n  --endpoint \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --framework \"express\" \\\n  --template \"templates\u002Fendpoint-test-template.spec.ts\"\n```\n\n**Generates tests for**:\n- Success responses\n- Validation errors\n- Authentication errors\n- Not found errors\n- Server errors\n\n**Returns**: Generated test code\n\n---\n\n## Templates\n\n### express-route-template.ts\n\nExpress.js route handler template.\n\n**Placeholders**:\n- `${ROUTE_PATH}` - API endpoint path\n- `${HTTP_METHOD}` - HTTP method (lowercase)\n- `${RESOURCE_NAME}` - Resource name (PascalCase)\n- `${VALIDATION_MIDDLEWARE}` - Validation middleware\n- `${AUTH_MIDDLEWARE}` - Authentication middleware\n\n### fastify-route-template.ts\n\nFastify route handler template (alternative).\n\n### graphql-resolver-template.ts\n\nGraphQL resolver template (alternative).\n\n### validation-zod-template.ts\n\nZod validation schema template.\n\n### endpoint-test-template.spec.ts\n\nIntegration test template with supertest.\n\n**Placeholders**:\n- `${ENDPOINT_PATH}` - Endpoint to test\n- `${HTTP_METHOD}` - HTTP method\n- `${TEST_CASES}` - Generated test cases\n\n---\n\n## Examples\n\nSee `examples\u002F` directory for reference implementations:\n\n1. **users-get.ts** - GET endpoint with auth\n2. **users-post.ts** - POST endpoint with validation\n3. **graphql-resolver.ts** - GraphQL mutation example\n\nEach example includes:\n- Route\u002Fresolver implementation\n- Validation schema\n- Error handling\n- Test file\n- Usage documentation\n\n---\n\n## Best Practices\n\n### REST API Design\n- **Use plural nouns** for resources (`\u002Fusers`, not `\u002Fuser`)\n- **Use HTTP methods correctly** (GET=read, POST=create, PUT\u002FPATCH=update, DELETE=remove)\n- **Nest resources properly** (`\u002Fusers\u002F:userId\u002Fposts\u002F:postId`)\n- **Return proper status codes** (200, 201, 400, 401, 404, 500)\n\n### Request Validation\n- **Validate all inputs** (body, params, query)\n- **Fail fast** (validate before business logic)\n- **Clear error messages** (tell user what's wrong)\n- **Sanitize inputs** (prevent injection attacks)\n\n### Error Handling\n- **Centralized error handler** (DRY principle)\n- **Consistent error format** (always same structure)\n- **Don't expose internals** (sanitize stack traces in production)\n- **Log errors** (for debugging)\n\n### Security\n- **Authentication** (verify identity)\n- **Authorization** (check permissions)\n- **Rate limiting** (prevent abuse)\n- **Input sanitization** (prevent XSS, SQL injection)\n\n### Testing\n- **Test happy path** (success cases)\n- **Test error cases** (validation, auth, not found)\n- **Test edge cases** (empty data, large data)\n- **Mock external dependencies** (database, APIs)\n\n---\n\n## Troubleshooting\n\n### Route Not Found (404)\n\n**Problem**: Endpoint returns 404 even though route is defined\n\n**Solutions**:\n1. Check route registration order (specific before generic)\n2. Verify path matches exactly (case-sensitive)\n3. Check middleware isn't blocking request\n4. Validate HTTP method matches\n\n### Validation Always Fails\n\n**Problem**: Valid requests fail validation\n\n**Solutions**:\n1. Check field names match exactly\n2. Verify data types are correct\n3. Check required vs optional fields\n4. Inspect validation error message\n\n### Tests Failing\n\n**Problem**: Integration tests don't pass\n\n**Solutions**:\n1. Ensure test database is seeded\n2. Check test fixtures are correct\n3. Verify mocks are set up properly\n4. Run tests with `--verbose` flag\n\n---\n\n## Success Criteria\n\n**This skill succeeds when**:\n- [ ] Endpoint responds with correct status codes\n- [ ] Request validation catches invalid inputs\n- [ ] Error handling works consistently\n- [ ] Tests cover success and error cases\n- [ ] Code follows REST\u002FGraphQL conventions\n- [ ] Documentation is clear and complete\n\n---\n\n**Auto-invoke this skill when creating API endpoints to ensure consistency and security** 🔒\n","# Backend API Endpoint Generator\n\nGenerate production-ready REST or GraphQL endpoints with request validation, error handling, and comprehensive tests.\n\n## When to Invoke\n\nAuto-invoke when user mentions:\n- \"Add endpoint\"\n- \"Create API\"\n- \"New route\"\n- \"Add route\"\n- \"Create API endpoint for [resource]\"\n\n## What This Does\n\n1. Generates route handler with proper HTTP methods\n2. Adds request validation (body, params, query)\n3. Implements error handling\n4. Creates test file with request\u002Fresponse tests\n5. Follows REST\u002FGraphQL conventions\n6. Includes authentication middleware (if needed)\n\n## Execution Steps\n\n### Step 1: Gather Endpoint Requirements\n\n**Ask user for endpoint details**:\n```\nEndpoint path: [e.g., \u002Fapi\u002Fusers\u002F:id]\nHTTP method: [GET, POST, PUT, PATCH, DELETE]\nResource name: [e.g., User, Post, Product]\n\nFramework:\n  - express (default)\n  - fastify\n  - nestjs\n  - graphql\n\nAuthentication required: [yes\u002Fno]\nRequest validation needed: [yes\u002Fno]\n```\n\n**Validate endpoint path**:\n- Use predefined function: `functions\u002Froute_validator.py`\n- Ensure RESTful conventions\n- Check path parameters syntax\n- No trailing slashes\n\n### Step 1.5: Verify Understanding (ToM Checkpoint) [EXECUTE]\n\n**IMPORTANT**: This step MUST be executed for high-stakes operations.\n\n**Before generating code, confirm interpretation with user**.\n\n**Display verification**:\n```\nI understood you want:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nEndpoint: {METHOD} {PATH}\nResource: {RESOURCE_NAME}\nFramework: {FRAMEWORK} (detected from package.json \u002F specified)\nAuth required: {yes\u002Fno}\nValidation needed: {yes\u002Fno}\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nAssumptions I'm making:\n- Using {VALIDATION_LIBRARY} for validation (detected from existing validators)\n- Error handling follows existing pattern in {ERROR_HANDLER_PATH}\n- Route will be registered at {ROUTE_PREFIX} prefix\n\nProceed with generation? [Y\u002Fn]\n```\n\n**Skip verification if** (HIGH-STAKES ONLY mode):\n- Simple CRUD operation (single resource, single path parameter)\n- User explicitly said \"quick\", \"just do it\", or \"skip confirmation\"\n- No custom authentication logic specified\n- Standard GET\u002FPOST\u002FPUT\u002FDELETE without complex business logic\n\n**Always verify if**:\n- Multiple path parameters (e.g., `\u002Fusers\u002F:userId\u002Fposts\u002F:postId`)\n- Custom authorization logic specified\n- Non-standard HTTP methods or patterns\n- GraphQL mutations with side effects\n- Endpoints involving financial or sensitive data\n\n### Step 1.8: Declare Belief State (Optional - ToM Anchor)\n\n**Before generating code, optionally declare explicit assumptions** (enabled by `tom_features.belief_anchors` in config).\n\n**Display belief state anchor**:\n```\n📌 BELIEF STATE\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nWhat I know (from context):\n✅ Framework: {FRAMEWORK} (from package.json)\n✅ TypeScript: {strict\u002Fnormal} mode (from tsconfig.json)\n✅ Validation: {LIBRARY} (from existing validators\u002F)\n\nWhat I'm assuming (inference):\n🔸 Error handler follows pattern in {PATH}\n🔸 Routes registered at {PREFIX} prefix\n🔸 Using {CONVENTION} commit messages\n\nWhat I don't know (using defaults):\n❓ Request logging preference (will include)\n❓ Rate limiting requirements (will skip)\n❓ Response envelope format (will use standard)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nAdjustments needed before I proceed?\n```\n\n**Skip belief anchor if**:\n- `tom_features.belief_anchors` is false in config\n- User said \"skip\", \"just do it\", \"quick\"\n- Simple endpoint with no custom logic\n\n**Show belief anchor if**:\n- Complex endpoint with multiple integrations\n- User profile indicates preference for detailed explanations\n- First endpoint in a new project (establishing patterns)\n\n### Step 2: Generate Route Handler\n\n**Based on HTTP method and framework**:\n\nUse predefined function: `functions\u002Fendpoint_generator.py`\n\n```bash\npython3 functions\u002Fendpoint_generator.py \\\n  --path \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --resource \"User\" \\\n  --framework \"express\" \\\n  --auth true \\\n  --validation true \\\n  --template \"templates\u002Fexpress-route-template.ts\" \\\n  --output \"src\u002Froutes\u002Fusers.ts\"\n```\n\n**Template includes**:\n- Route definition\n- Request validation middleware\n- Controller\u002Fhandler function\n- Error handling\n- Response formatting\n- TypeScript types\n\n### Step 3: Generate Validation Schema\n\n**Use predefined function**: `functions\u002Fvalidation_generator.py`\n\n```bash\npython3 functions\u002Fvalidation_generator.py \\\n  --resource \"User\" \\\n  --method \"POST\" \\\n  --fields \"name:string:required,email:email:required,age:number:optional\" \\\n  --library \"zod\" \\\n  --output \"src\u002Fvalidators\u002Fuser.validator.ts\"\n```\n\n**Supported validation libraries**:\n- Zod (default, TypeScript-first)\n- Joi (JavaScript schema)\n- Yup (object schema)\n- Express-validator (middleware-based)\n\n**Output example (Zod)**:\n```typescript\nimport { z } from 'zod';\n\nexport const createUserSchema = z.object({\n  name: z.string().min(1),\n  email: z.string().email(),\n  age: z.number().optional(),\n});\n\nexport type CreateUserInput = z.infer\u003Ctypeof createUserSchema>;\n```\n\n### Step 4: Generate Error Handling Middleware\n\n**Use predefined function**: `functions\u002Ferror_handler_generator.py`\n\n```bash\npython3 functions\u002Ferror_handler_generator.py \\\n  --framework \"express\" \\\n  --template \"templates\u002Ferror-handler-template.ts\" \\\n  --output \"src\u002Fmiddleware\u002FerrorHandler.ts\"\n```\n\n**Error handler includes**:\n- HTTP status code mapping\n- Error response formatting\n- Logging integration\n- Development vs production modes\n- Validation error handling\n\n### Step 5: Generate Test File\n\n**Use predefined function**: `functions\u002Ftest_generator.py`\n\n```bash\npython3 functions\u002Ftest_generator.py \\\n  --endpoint \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --framework \"express\" \\\n  --template \"templates\u002Fendpoint-test-template.spec.ts\" \\\n  --output \"tests\u002Froutes\u002Fusers.test.ts\"\n```\n\n**Test template includes**:\n- Success case (200\u002F201)\n- Validation errors (400)\n- Not found (404)\n- Unauthorized (401)\n- Server errors (500)\n- Edge cases\n\n**Example test**:\n```typescript\ndescribe('GET \u002Fapi\u002Fusers\u002F:id', () => {\n  it('returns user when found', async () => {\n    const response = await request(app)\n      .get('\u002Fapi\u002Fusers\u002F123')\n      .expect(200);\n\n    expect(response.body).toMatchObject({\n      id: '123',\n      name: expect.any(String),\n    });\n  });\n\n  it('returns 404 when user not found', async () => {\n    await request(app)\n      .get('\u002Fapi\u002Fusers\u002F999')\n      .expect(404);\n  });\n});\n```\n\n### Step 6: Generate API Documentation Comment\n\n**JSDoc or OpenAPI annotation**:\n\n```typescript\n\u002F**\n * @route GET \u002Fapi\u002Fusers\u002F:id\n * @description Get user by ID\n * @access Private\n * @param {string} id - User ID\n * @returns {User} User object\n * @throws {404} User not found\n * @throws {401} Unauthorized\n *\u002F\n```\n\n### Step 7: Show Endpoint Summary\n\n**Display generated files and usage**:\n\n```\n✅ Endpoint Created: GET \u002Fapi\u002Fusers\u002F:id\n\nStructure:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📁 src\u002F\n   ├── routes\u002Fusers.ts                (Route handler)\n   ├── validators\u002Fuser.validator.ts   (Request validation)\n   └── middleware\u002FerrorHandler.ts     (Error handling)\n\n📁 tests\u002F\n   └── routes\u002Fusers.test.ts           (Integration tests)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nRoute Registration:\nimport { userRoutes } from '.\u002Froutes\u002Fusers';\napp.use('\u002Fapi', userRoutes);\n\nTest:\ncurl http:\u002F\u002Flocalhost:3000\u002Fapi\u002Fusers\u002F123\n# or\nnpm test -- users.test.ts\n\nNext Steps:\n1. Implement business logic in controller\n2. Connect to database\u002Fservice layer\n3. Run tests: npm test\n4. Test with Postman\u002FThunder Client\n```\n\n---\n\n## Predefined Functions\n\n### 1. route_validator.py\n\nValidates route path follows REST conventions.\n\n**Usage**:\n```bash\npython3 functions\u002Froute_validator.py --path \"\u002Fapi\u002Fusers\u002F:id\" --method \"GET\"\n```\n\n**Checks**:\n- RESTful naming (plural resources)\n- Path parameter syntax (`:id` or `{id}`)\n- No trailing slashes\n- HTTP method matches intent\n\n**Returns**: Valid path or error message\n\n---\n\n### 2. endpoint_generator.py\n\nGenerates endpoint handler from template.\n\n**Usage**:\n```bash\npython3 functions\u002Fendpoint_generator.py \\\n  --path \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --resource \"User\" \\\n  --framework \"express\" \\\n  --auth true \\\n  --validation true \\\n  --template \"templates\u002Fexpress-route-template.ts\"\n```\n\n**Parameters**:\n- `--path`: API endpoint path\n- `--method`: HTTP method\n- `--resource`: Resource name (singular, PascalCase)\n- `--framework`: Backend framework\n- `--auth`: Include auth middleware\n- `--validation`: Include validation middleware\n- `--template`: Template file path\n\n**Returns**: Generated endpoint code\n\n---\n\n### 3. validation_generator.py\n\nGenerates request validation schema.\n\n**Usage**:\n```bash\npython3 functions\u002Fvalidation_generator.py \\\n  --resource \"User\" \\\n  --method \"POST\" \\\n  --fields \"name:string:required,email:email:required\" \\\n  --library \"zod\"\n```\n\n**Supported field types**:\n- `string`, `number`, `boolean`\n- `email`, `url`, `uuid`\n- `array`, `object`\n- `date`, `datetime`\n\n**Returns**: Validation schema code\n\n---\n\n### 4. error_handler_generator.py\n\nGenerates error handling middleware.\n\n**Usage**:\n```bash\npython3 functions\u002Ferror_handler_generator.py \\\n  --framework \"express\" \\\n  --template \"templates\u002Ferror-handler-template.ts\"\n```\n\n**Returns**: Error handler middleware code\n\n---\n\n### 5. test_generator.py\n\nGenerates endpoint integration tests.\n\n**Usage**:\n```bash\npython3 functions\u002Ftest_generator.py \\\n  --endpoint \"\u002Fapi\u002Fusers\u002F:id\" \\\n  --method \"GET\" \\\n  --framework \"express\" \\\n  --template \"templates\u002Fendpoint-test-template.spec.ts\"\n```\n\n**Generates tests for**:\n- Success responses\n- Validation errors\n- Authentication errors\n- Not found errors\n- Server errors\n\n**Returns**: Generated test code\n\n---\n\n## Templates\n\n### express-route-template.ts\n\nExpress.js route handler template.\n\n**Placeholders**:\n- `${ROUTE_PATH}` - API endpoint path\n- `${HTTP_METHOD}` - HTTP method (lowercase)\n- `${RESOURCE_NAME}` - Resource name (PascalCase)\n- `${VALIDATION_MIDDLEWARE}` - Validation middleware\n- `${AUTH_MIDDLEWARE}` - Authentication middleware\n\n### fastify-route-template.ts\n\nFastify route handler template (alternative).\n\n### graphql-resolver-template.ts\n\nGraphQL resolver template (alternative).\n\n### validation-zod-template.ts\n\nZod validation schema template.\n\n### endpoint-test-template.spec.ts\n\nIntegration test template with supertest.\n\n**Placeholders**:\n- `${ENDPOINT_PATH}` - Endpoint to test\n- `${HTTP_METHOD}` - HTTP method\n- `${TEST_CASES}` - Generated test cases\n\n---\n\n## Examples\n\nSee `examples\u002F` directory for reference implementations:\n\n1. **users-get.ts** - GET endpoint with auth\n2. **users-post.ts** - POST endpoint with validation\n3. **graphql-resolver.ts** - GraphQL mutation example\n\nEach example includes:\n- Route\u002Fresolver implementation\n- Validation schema\n- Error handling\n- Test file\n- Usage documentation\n\n---\n\n## Best Practices\n\n### REST API Design\n- **Use plural nouns** for resources (`\u002Fusers`, not `\u002Fuser`)\n- **Use HTTP methods correctly** (GET=read, POST=create, PUT\u002FPATCH=update, DELETE=remove)\n- **Nest resources properly** (`\u002Fusers\u002F:userId\u002Fposts\u002F:postId`)\n- **Return proper status codes** (200, 201, 400, 401, 404, 500)\n\n### Request Validation\n- **Validate all inputs** (body, params, query)\n- **Fail fast** (validate before business logic)\n- **Clear error messages** (tell user what's wrong)\n- **Sanitize inputs** (prevent injection attacks)\n\n### Error Handling\n- **Centralized error handler** (DRY principle)\n- **Consistent error format** (always same structure)\n- **Don't expose internals** (sanitize stack traces in production)\n- **Log errors** (for debugging)\n\n### Security\n- **Authentication** (verify identity)\n- **Authorization** (check permissions)\n- **Rate limiting** (prevent abuse)\n- **Input sanitization** (prevent XSS, SQL injection)\n\n### Testing\n- **Test happy path** (success cases)\n- **Test error cases** (validation, auth, not found)\n- **Test edge cases** (empty data, large data)\n- **Mock external dependencies** (database, APIs)\n\n---\n\n## Troubleshooting\n\n### Route Not Found (404)\n\n**Problem**: Endpoint returns 404 even though route is defined\n\n**Solutions**:\n1. Check route registration order (specific before generic)\n2. Verify path matches exactly (case-sensitive)\n3. Check middleware isn't blocking request\n4. Validate HTTP method matches\n\n### Validation Always Fails\n\n**Problem**: Valid requests fail validation\n\n**Solutions**:\n1. Check field names match exactly\n2. Verify data types are correct\n3. Check required vs optional fields\n4. Inspect validation error message\n\n### Tests Failing\n\n**Problem**: Integration tests don't pass\n\n**Solutions**:\n1. Ensure test database is seeded\n2. Check test fixtures are correct\n3. Verify mocks are set up properly\n4. Run tests with `--verbose` flag\n\n---\n\n## Success Criteria\n\n**This skill succeeds when**:\n- [ ] Endpoint responds with correct status codes\n- [ ] Request validation catches invalid inputs\n- [ ] Error handling works consistently\n- [ ] Tests cover success and error cases\n- [ ] Code follows REST\u002FGraphQL conventions\n- [ ] Documentation is clear and complete\n\n---\n\n**Auto-invoke this skill when creating API endpoints to ensure consistency and security** 🔒\n",{"name":5,"version":51,"description":7,"allowed-tools":52},"1.0.0","Read, Write, Edit, Grep, Glob, Bash","main","f2ec4b3b9133d34eeaf9b38e4b0a97e8e5705a7f","benchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint",0,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard","https:\u002F\u002Fgithub.com\u002FJSGforever","2026-08-29 18:27:56",{"source":8,"skillName":5,"commands":61,"prompt":71,"zipAvailable":72},[62,65,68],{"tool":63,"command":64},"npx","npx skills add JSGforever\u002Fskillguard --skill backend-endpoint",{"tool":66,"command":67},"bunx","bunx skills add JSGforever\u002Fskillguard --skill backend-endpoint",{"tool":69,"command":70},"pnpm","pnpm dlx skills add JSGforever\u002Fskillguard --skill backend-endpoint","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002FSKILL.md",true,[74,80,84,88,92,96,100],{"path":75,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":78,"sourceHtmlUrl":79},"examples\u002Fusers-get.ts","SCRIPT","脚本",1039,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Fexamples\u002Fusers-get.ts",{"path":81,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":82,"sourceHtmlUrl":83},"examples\u002Fusers-post.ts",1290,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Fexamples\u002Fusers-post.ts",{"path":85,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":86,"sourceHtmlUrl":87},"functions\u002Fendpoint_generator.py",4087,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Ffunctions\u002Fendpoint_generator.py",{"path":89,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":90,"sourceHtmlUrl":91},"functions\u002Froute_validator.py",4574,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Ffunctions\u002Froute_validator.py",{"path":93,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":94,"sourceHtmlUrl":95},"functions\u002Fvalidation_generator.py",3680,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Ffunctions\u002Fvalidation_generator.py",{"path":97,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":98,"sourceHtmlUrl":99},"templates\u002Fendpoint-test-template.spec.ts",132,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Ftemplates\u002Fendpoint-test-template.spec.ts",{"path":101,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":102,"sourceHtmlUrl":103},"templates\u002Fexpress-route-template.ts",701,"https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__alekspetrov--backend-endpoint\u002Ftemplates\u002Fexpress-route-template.ts",[105,134,150,176,198,217],{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":114,"publishedAt":46},"01M71HY2SNXBA9Q00WZDTZQ31Z","skillguard-codex-scanner","Hybrid deterministic+LLM agent-skill security scanner. Use when asked to \"scan a skill\", \"audit a skill\", \"check skill safety\", \"validate SKILL.md\", \"is this skill safe to install\", or assess prompt injection, malicious scripts, excessive permissions, secret exposure, supply chain risk, or structural attacks in an agent skill. Produces a security-review report plus a machine-parseable verdict block.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fsrc\u002Fskillguard\u002Fstatic_scanner\u002Fskillguard-codex-scanner\u002FSKILL.md",[111],{"categoryNo":112,"categoryName":113,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000023","Skill与智能体开发",[115,116,117,118,119,120,121,122,123,124,125,126,41,127,128,129,130,131,132,133],"scanner","skillguard codex scanner","skillguard","codex","chain","skill security","security-review","review report","structural","secret","prompt injection","security scanner","review","malicious","permissions","exposure","audit","scripts","safe",{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":138,"licenseFileUrl":6,"sourceHtmlUrl":139,"categories":140,"keywords":146,"publishedAt":46},"01M71HY0SPKTT3S27BC2HPAC5M","data-exfiltrator","Analyzes data files","MIT","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Fsmoke-one-skill\u002Fasset1__cisco-ai-defense--data-exfiltrator\u002FSKILL.md",[141],{"categoryNo":142,"categoryName":143,"taxonomyType":144,"taxonomyTypeDesc":145},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[147,148,149],"data","data exfiltrator","files",{"skillNo":151,"name":152,"nameZh":6,"description":153,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":154,"categories":155,"keywords":156,"publishedAt":46},"01M71HXVS9EMN44BGDW215FZ72","real-time-collaboration-engine","Build real-time collaborative editing with WebSockets, OT\u002FCRDT conflict resolution, and presence awareness. Implements cursor tracking, optimistic updates, and offline sync. Use for collaborative editors, whiteboards, video editing. Activate on \"real-time collaboration\", \"WebSocket sync\", \"multiplayer editing\", \"CRDT\", \"presence awareness\". NOT for simple chat, request-response APIs, or single-user apps.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--real-time-collaboration-engine\u002FSKILL.md",[],[157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,40,172,173,174,175],"time","real time collaboration engine","real time collaboration","collaboration","engine","real time","Video","reliability","video editing","performance","conflict resolution","presence","access","apps","updates","activate","optimizer","react","streaming",{"skillNo":177,"name":178,"nameZh":6,"description":179,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":180,"categories":181,"keywords":185,"publishedAt":46},"01M71HXP6CTY4KFN0QVMMN0V7J","react-performance-optimizer","Optimize React apps for 60fps performance. Implements memoization, virtualization, code splitting, bundle optimization. Use for slow renders, large lists, bundle bloat. Activate on \"React performance\", \"slow render\", \"useMemo\", \"bundle size\", \"virtualization\". NOT for backend optimization, non-React frameworks, or premature optimization.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--react-performance-optimizer\u002FSKILL.md",[182],{"categoryNo":183,"categoryName":184,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000009","前端开发",[166,186,173,174,187,188,189,190,191,192,157,193,194,170,40,195,172,175,196,197],"react performance optimizer","react performance","performance optimizer","app","nextjs","expert","re","render","2025","code","router","strategies",{"skillNo":199,"name":200,"nameZh":6,"description":201,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":202,"categories":203,"keywords":205,"publishedAt":46},"01M71HXH7QXSQB4QTDZ7SP7YXQ","llm-streaming-response-handler","Build production LLM streaming UIs with Server-Sent Events, real-time token display, cancellation, error recovery. Handles OpenAI\u002FAnthropic\u002FClaude streaming APIs. Use for chatbots, AI assistants, real-time text generation. Activate on \"LLM streaming\", \"SSE\", \"token stream\", \"chat UI\", \"real-time AI\". NOT for batch processing, non-streaming APIs, or WebSocket bidirectional chat.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--llm-streaming-response-handler\u002FSKILL.md",[204],{"categoryNo":183,"categoryName":184,"taxonomyType":20,"taxonomyTypeDesc":21},[206,175,207,45,208,209,166,157,210,211,212,40,172,173,213,174,214,215,216,35],"llm streaming response handler","handler","processing","retry","chat ui","error recovery","critical","batch","display","text","server",{"skillNo":218,"name":219,"nameZh":6,"description":220,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":221,"categories":222,"keywords":228,"publishedAt":46},"01M71HXCB0E1YRKYW1Y8T0Y106","github-actions-pipeline-builder","Build production CI\u002FCD pipelines with GitHub Actions. Implements matrix builds, caching, deployments, testing, security scanning. Use for automated testing, deployments, release workflows. Activate on \"GitHub Actions\", \"CI\u002FCD\", \"workflow\", \"deployment pipeline\", \"automated testing\". NOT for Jenkins\u002FCircleCI, manual deployments, or non-GitHub repositories.","https:\u002F\u002Fgithub.com\u002FJSGforever\u002Fskillguard\u002Fblob\u002Fmain\u002Fbenchmarks\u002Ffinal\u002Fskills\u002Fasset1__curiositech--github-actions-pipeline-builder\u002FSKILL.md",[223,224,227],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":225,"categoryName":226,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000011","运维与部署",{"categoryNo":112,"categoryName":113,"taxonomyType":20,"taxonomyTypeDesc":21},[229,230,231,232,233,234,235,164,191,236,237,238,172,197,239,35,240,34,33,241],"github actions pipeline builder","actions","github actions","pipeline builder","github","builder","pipeline","testing","ci","workflows","run","release","git"]