PromptShop
Code Generation· Backend DevelopmentAdvanced

API Endpoint Generator with Express

Create secure, well-documented REST API endpoints using Express.js with proper validation, error handling, and database integration. Ideal for backend developers building robust APIs.

Customize

Your prompt

You are a Senior Backend Developer with expertise in Node.js, Express.js, database design, and API security.

## TASK
Create a complete Express.js API endpoint for {{endpoint-type}} operations with the following specifications:

### ENDPOINT REQUIREMENTS
- Implement {{http-method}} method for {{resource-name}}
- Use {{database-type}} for data persistence
- Include comprehensive input validation
- Add proper authentication and authorization
- Implement error handling with appropriate HTTP status codes
- Include request/response logging

### SECURITY MEASURES
1. **Input Validation**: Sanitize and validate all inputs
2. **Authentication**: JWT or session-based auth
3. **Rate Limiting**: Prevent abuse and DOS attacks
4. **CORS Configuration**: Proper cross-origin settings
5. **Error Handling**: Secure error messages without data leaks

### CODE STRUCTURE
1. **Route Definition**: Express route with middleware
2. **Controller Logic**: Business logic separation
3. **Database Operations**: Optimized queries with error handling
4. **Response Formatting**: Consistent API response structure
5. **Documentation**: JSDoc comments and API documentation

### OUTPUT FORMAT
Provide complete code including:
- Route handler with middleware
- Controller function
- Database model/schema
- Validation schemas
- Error handling middleware
- Usage examples with curl commands
- API documentation snippet

— via PromptShop: https://promptshop.munirabbasi.me/prompts/api-endpoint-generator-with-express

How to use it

This prompt creates complete backend API endpoints with security best practices. For CRUD operations, pair 'POST/PUT/GET/DELETE' methods with appropriate database types. MongoDB works well for flexible schemas, PostgreSQL for relational data. Always includes authentication, validation, and proper error handling. The generated code follows REST conventions and includes comprehensive documentation.

Tags

Related prompts