P
💻DeveloppementAdvancedAll AIs

Create a Complete REST API from A to Z

A complete prompt to generate a professional REST API with authentication, validation, documentation, and integrated tests.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un développeur backend senior spécialisé en conception d'API REST. Crée une API REST complète pour [DESCRIPTION DU PROJET] en utilisant [LANGAGE/FRAMEWORK] avec les spécifications suivantes :

1. **Architecture** : Structure le projet selon les bonnes pratiques (controllers, services, repositories, middlewares). Fournis l'arborescence complète des fichiers.

2. **Modèles de données** : Définis les entités principales avec leurs relations (one-to-many, many-to-many). Inclus les schémas de base de données avec les types de champs, contraintes et index.

3. **Endpoints CRUD** : Pour chaque ressource, implémente :
   - GET (liste paginée avec filtres et tri)
   - GET by ID (avec relations imbriquées)
   - POST (avec validation des données entrantes)
   - PUT/PATCH (mise à jour partielle et complète)
   - DELETE (soft delete si pertinent)

4. **Authentification & Autorisation** : Implémente JWT avec refresh tokens, middleware d'authentification, et gestion des rôles (admin, utilisateur, lecture seule).

5. **Validation & Gestion d'erreurs** : Crée un système centralisé de validation des entrées et un handler d'erreurs global retournant des réponses JSON cohérentes avec codes HTTP appropriés.

6. **Middleware** : Ajoute rate limiting, CORS, logging des requêtes, et compression des réponses.

7. **Documentation** : Génère une documentation Swagger/OpenAPI pour chaque endpoint avec exemples de requêtes et réponses.

8. **Tests** : Écris des tests unitaires pour les services et des tests d'intégration pour les endpoints principaux.

Pour chaque fichier, fournis le code complet et commenté. Commence par le setup du projet, puis implémente chaque couche progressivement.

Why this prompt works

<p>This prompt guides the AI to produce a production-quality REST API covering all essential layers. By specifying <strong>[PROJECT DESCRIPTION]</strong> (e.g., "a collaborative task management platform") and <strong>[LANGUAGE/FRAMEWORK]</strong> (e.g., "Node.js with Express" or "Python with FastAPI"), you get code adapted to your exact context.</p><p>The 8-point structure forces the AI to not forget anything: from file architecture to tests, through security and documentation. Each section is detailed enough to avoid superficial answers, while letting the AI adapt patterns to your tech stack.</p><p><strong>Usage tip</strong>: for complex projects, first submit the complete prompt to get the overall architecture, then request detailed implementation section by section. You can also add specific constraints such as a particular database (PostgreSQL, MongoDB), a target hosting (Docker, serverless), or performance requirements (Redis cache, cursor-based pagination).</p>

Use Cases

Create the backend of a SaaS application from scratchQuickly prototype an API for a startup MVPModernize a legacy API into a clean REST architecturePrepare a backend project for a technical interview

Expected Output

A complete REST API project with file tree, commented source code for each layer (routes, controllers, services, models), JWT authentication setup, validation middleware, Swagger documentation, and unit and integration test examples.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementIntermediateChatGPT

Create an Optimized Production Dockerfile

Create a multi-stage Dockerfile optimized for production with maximum security, lightweight image, and best practices.

3153
💻DeveloppementIntermediateChatGPT

Write Integration Tests for an API

Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.

2952
💻DeveloppementIntermediateAll AIs

Design a Complete REST API

Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.

4150
💻DeveloppementIntermediateAll AIs

AI-Assisted Complete Code Review

A complete prompt to get an in-depth code review covering bugs, security, performance, readability, and best practices, with concrete fixes.

020