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
Sora Prompt for Creating E2E Tests
End-to-end (E2E) tests are essential for ensuring application reliability, but writing them remains time-consuming and repetitive. Sora, thanks to its advanced generation capabilities, makes it possible to automate the creation of complete E2E test scenarios in seconds. By formulating a precise prompt describing user journeys, expected interactions, and validation criteria, you obtain structured test suites covering nominal cases as well as edge cases. The prompt engineering approach applied to Sora transforms how QA and development teams approach test coverage. Instead of starting from a blank page, you describe the expected behavior of your application in natural language, and Sora generates the corresponding test code with appropriate assertions. This method significantly reduces the time needed to set up an E2E suite while maintaining a professional quality level. Whether you use Playwright, Cypress, or Selenium, the prompts presented here adapt to your technical stack and the complexity of your application.
Implement rate limiting
Protect APIs from abuse
GitHub Copilot Prompt for Creating a REST API
GitHub Copilot has become an essential assistant for developers looking to accelerate the creation of REST APIs. Thanks to its direct integration into the code editor, it understands the context of your project and generates structured code in real time. Whether you work with Node.js and Express, Python and FastAPI, or Java and Spring Boot, Copilot adapts to your tech stack to produce endpoints conforming to REST conventions. The main challenge lies in formulating the prompt: a well-structured prompt yields a complete API with data validation, error handling, authentication, and documentation. A vague prompt, on the other hand, will produce generic code requiring many adjustments. In this guide, we offer an optimized prompt that fully leverages GitHub Copilot's capabilities to generate a professional, testable, production-ready REST API. You will also discover variants adapted to your experience level as well as practical tips to get the most out of this tool on a daily basis.
Implement CSP with nonces
Prevent XSS with strict CSP