P
💻DeveloppementIntermediateGemini

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:

  1. Layered architecture (routes → controllers → services → repositories)
  2. Input validation with typed schemas
  3. Centralized error handling with appropriate HTTP status codes
  4. JWT authentication middleware
  5. Pagination, filtering, and sorting on list endpoints
  6. Configured rate limiting and CORS
  7. Auto-generated OpenAPI/Swagger documentation
  8. 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

Answer 3 questions and Léa tailors the prompt to your situation.

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

Create a REST API

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).

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

💻DeveloppementIntermediateAll AIs

Generate Mocks and Fixtures for Your Automated Tests

A prompt to automatically generate realistic mocks, stubs and data fixtures adapted to your test framework and use cases.

091
💻DeveloppementIntermediateAll AIs

Automatically Generate Unit Tests with AI

Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.

0223
💻DeveloppementIntermediateGemini

Create a Python Automation Script

Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.

24239
💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

40233