Gemini Prompt to Create a REST API
Creating a REST API is a fundamental skill in modern development, but it involves many architectural decisions: choice of framework, endpoint structure, authentication management, data validation, and documentation. Google Gemini excels at generating structured code and can guide you through each step of this process. Using a well-crafted prompt, you not only get the skeleton of your API but also best practices built in from the start: proper HTTP codes, centralized error handling, security middleware, and layered architecture. Whether you're building a microservice for a personal project or an enterprise API designed to handle thousands of requests, Gemini adapts its response to the requested complexity level. The main benefit is time savings during the scaffolding phase: instead of spending hours manually configuring each component, you get a solid, coherent foundation in seconds, which you can then customize to your specific business needs.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Act as a senior backend architect specializing in REST API design. Create a complete REST API to manage [RESOURCE, e.g., products] with the following specifications:
Technical stack: [Node.js/Express | Python/FastAPI | Java/Spring Boot]
Database: [PostgreSQL | MongoDB | MySQL]
Required endpoints:
- GET /api/[resource] — Paginated list with filters and sorting
- GET /api/[resource]/:id — Resource detail
- POST /api/[resource] — Create with validation
- PUT /api/[resource]/:id — Full update
- PATCH /api/[resource]/:id — Partial update
- DELETE /api/[resource]/:id — Deletion (soft delete)
Technical requirements:
- Layered architecture (routes → controllers → services → repositories)
- Input validation with typed schemas
- Centralized error handling with appropriate HTTP status codes
- JWT authentication middleware
- Pagination, filtering, and sorting on list endpoints
- Configured rate limiting and CORS
- Auto-generated OpenAPI/Swagger documentation
- Environment variables for configuration
For each file, provide the full commented code, the project tree, installation commands, and a sample .env file. Also include 3 example curl requests to test the main endpoints.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
This prompt works by assigning a precise expert role that activates Gemini's architectural knowledge, combined with a structured list of requirements that leaves no ambiguity about the expected deliverable. The explicit mention of layered architecture and patterns like soft delete or pagination forces the model to produce production-quality code rather than a simple tutorial. Finally, the request for complete files with a directory tree and installation commands guarantees an immediately usable result.
Use Cases
Variants
Expected Output
You will obtain a complete project with a file tree, source code for each layer (routes, controllers, services, models), database configuration, authentication and error-handling middlewares, and Swagger documentation. All of this comes with installation instructions, an example .env file, and ready-to-execute curl commands to validate the proper functioning of each endpoint.
Frequently Asked Questions
Which framework does Gemini recommend most often for building a REST API?
Gemini produces excellent results with Express.js (Node.js), FastAPI (Python), and Spring Boot (Java). The choice depends on your context: Express is ideal for its simplicity and npm ecosystem, FastAPI shines with its automatic validation and built-in documentation, while Spring Boot suits enterprise Java environments. Always specify your framework in the prompt to get idiomatic, optimized code.
How can I ask Gemini to handle errors properly in the API?
Explicitly mention centralized error handling in your prompt. Ask for a global error middleware, custom error classes (NotFoundError, ValidationError, UnauthorizedError), and a standardized error response format including the HTTP code, a human-readable message, and a correlation ID. Gemini will then structure try/catch blocks consistently and return uniform error responses across all endpoints.
Can Gemini also generate tests for the REST API?
Absolutely. Add an explicit request to your prompt for unit tests for services and integration tests for endpoints. Specify the desired testing framework (Jest, Pytest, JUnit) and ask for realistic data fixtures. Gemini can generate tests covering nominal cases, error cases (non-existent resource, invalid data, unauthorized access), and edge cases (pagination beyond results, missing optional fields).
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour un résultat exploitable, précisez la ressource et ses champs (ex. : produit avec nom, prix, stock) et le format de réponse attendu. Sinon, l’API générique restera superficielle. Astuce : demandez à Gemini d’écrire d’abord l’arborescence, puis de générer les fichiers un par un — cela réduit les erreurs et facilite les ajustements. Ajoutez aussi des tests unitaires et un Dockerfile pour aller plus loin.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Implement CSP with nonces
Prevent XSS with strict CSP
DALL-E Prompt to Generate JavaScript Code
DALL-E, the image generation model developed by OpenAI, is not designed to produce executable JavaScript code. However, it can play a valuable complementary role in a JavaScript developer's workflow. DALL-E excels at creating visuals related to development: user interface mockups, architecture diagrams, data flow schemas, or illustrations to document your code. By crafting precise prompts, you can obtain visual representations of complex JavaScript concepts like closures, the event loop, or design patterns. These visuals then serve as references for implementing your code, creating attractive technical documentation, or designing educational materials. The approach is to use DALL-E as a rapid visual prototyping tool: generate a UI mockup, then translate it into JavaScript components. This method accelerates the design phase and reduces back-and-forth between designers and developers. In this guide, we offer optimized prompts to get the most out of DALL-E in your JavaScript development process, from UI prototyping to visual documentation of your code.
Create a High-Performance Scalable Redis Cache System
A complete prompt to design and implement a Redis cache system with invalidation strategies, error handling and monitoring.
Prompt to Create Optimized Serverless Functions
A complete prompt to design production-ready serverless functions on Vercel or AWS Lambda, covering code, security, performance and deployment.