P

Gemini Prompt for Creating a REST API

Creating a REST API is a fundamental skill in modern development, but it involves many architectural decisions: framework choice, endpoint structure, authentication handling, data validation, and documentation. Google Gemini excels at generating structured code and can guide you through every step of this process. By using a well-designed prompt, you get not only the skeleton of your API but also built-in best practices from the start: appropriate HTTP codes, centralized error handling, security middleware, and layered architecture. Whether you're building a microservice for a personal project or an enterprise API meant to handle thousands of requests, Gemini adapts its response to the requested complexity level. The major advantage is time saved on the scaffolding phase: instead of spending hours manually configuring each component, you get a solid and consistent foundation in seconds, which you can then customize to your specific business needs.

The prompt

Gemini

Act as a senior backend architect specialized in REST API design. Create a complete REST API to manage [RESOURCE, e.g., products] with the following specifications:

Tech 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 details
  • POST /api/[resource] — Creation 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 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 complete commented code, the project tree, installation commands, and an example .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 it works

This prompt works due to the precise expert role attribution 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 project tree and installation commands guarantees a directly usable result.

Expected result

You will get a complete project with the file tree, source code for each layer (routes, controllers, services, models), database configuration, authentication and error handling middlewares, as well as Swagger documentation. Everything will be accompanied by installation instructions, an example .env file, and ready-to-run curl commands to validate the proper functioning of each endpoint.

Variants by level

FAQ

Which framework does Gemini most often recommend for creating a REST API?
Gemini generates 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 and optimized code.
How to ask Gemini to properly handle errors 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 readable message, and a correlation ID. Gemini will then structure try/catch blocks consistently and return uniform error responses across all endpoints.
Can Gemini be used to also generate tests for the REST API?
Absolutely. Add to your prompt an explicit request 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 (missing resource, invalid data, unauthorized access), and edge cases (pagination beyond results, missing optional fields).

Related prompts

How to use this prompt

  1. Copy the prompt with the button above.
  2. Paste it into ChatGPT, Claude or your favorite AI assistant.
  3. Replace the bracketed variables with your details, then refine the result.

About Prompt Guide

Prompt Guide is a free library of 4800+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.

More prompts to explore

Gemini Prompt for Creating an Advertising Script

Creating a compelling advertising script requires creativity, knowledge of persuasion mechanisms, and mastery of format constraints. Google's AI model, Gemini, excels at generating marketing content...

Gemini Prompt for Creating an Email Campaign

Gemini, Google's artificial intelligence model, excels at creating email campaigns thanks to its ability to analyze complex marketing data and generate persuasive content adapted to each audience segment.

Gemini Prompt for Creating an FAQ

Creating a relevant and comprehensive FAQ is a strategic exercise for any website, service, or product. A good FAQ anticipates user questions,

Gemini Prompt for Creating E2E Tests

End-to-end (E2E) tests are essential to ensure the overall functioning of an application, but writing them is often time-consuming and repetitive. Gemini, Google's AI model, excels in generating structured code and can significantly speed up the creation of comprehensive E2E test suites. By providing the technical context of your application — technology stack, critical user journeys, and the test framework used — Gemini can produce robust test scenarios covering both main flows and edge cases. Whether you use Playwright, Cypress, or Selenium, the AI adapts to your framework's conventions to generate directly usable code. The prompt engineering approach allows you to specify the desired coverage level, preferred selector patterns, and test data management strategy. The result: maintainable, readable tests aligned with your team's best practices, produced in a fraction of the usual time.

Gemini Prompt for Creating Illustrations

Gemini, Google's artificial intelligence model, offers remarkable capabilities for creating original and detailed illustrations. Whether you are a...

Gemini Prompt for Creating Images

Gemini, Google's artificial intelligence model, now integrates advanced image generation capabilities directly into its responses. Unlike classic image generators, Gemini combines deep language understanding with visual generation, allowing you to create images from highly detailed text descriptions in English. Whether you're a graphic designer looking to quickly prototype concepts, an entrepreneur creating visuals for social media, or simply curious about AI-assisted creation, mastering the art of prompting Gemini will save you considerable time. The key lies in the precision of your instructions: artistic style, composition, lighting, color palette, and overall atmosphere are all parameters that Gemini can interpret to produce striking results. In this guide, you'll discover an optimized main prompt as well as variants suited to your skill level, to get the most out of image generation with Gemini.

Go further

Get new prompts every week

Join our newsletter.