P
💻DeveloppementIntermediateClaude

Claude Prompt for Creating a REST API

Creating a REST API is a fundamental task of modern backend development. Whether you are building a microservice, a SaaS application, or a full platform, a well-structured API is the backbone of your architecture. Claude excels at generating complete REST APIs following best practices: clear project structure, data validation, error handling, authentication, OpenAPI documentation, and tests. Rather than starting from scratch or copying outdated boilerplates, you can precisely describe your business needs to Claude and get a production-ready API in minutes. The major advantage lies in Claude's ability to adapt the code to your framework of choice (Express, FastAPI, NestJS, Django REST, Spring Boot) while applying RESTful conventions: appropriate HTTP verbs, correct status codes, pagination, filtering, and versioning. This guide provides optimized prompts to get the most out of Claude in designing and implementing your REST APIs, from quick prototypes to complete microservice architectures.

Paste in your AI

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

You are a senior backend architect specialized in designing RESTful APIs. Create a complete REST API for a [BUSINESS_DOMAIN, e.g.: library management] application with the following specifications:

Technical stack: [Framework, e.g.: Node.js with Express and TypeScript]
Database: [DATABASE, e.g.: PostgreSQL with Prisma ORM]

Main resources:

  • [Resource 1, e.g.: Books (title, author, ISBN, category, availability)]
  • [Resource 2, e.g.: Members (name, email, subscription, history)]
  • [Resource 3, e.g.: Loans (book, member, borrow_date, return_date)]

Requirements:

  1. Layered architecture (routes → controllers → services → repositories)
  2. Full CRUD endpoints for each resource with appropriate HTTP verbs
  3. Input validation with schemas (Zod or Joi)
  4. Centralized error handling with standard HTTP codes
  5. Pagination, sorting, and filtering on list endpoints
  6. JWT authentication with route protection middleware
  7. Relationships between resources with nested endpoints
  8. Auto-generated OpenAPI/Swagger documentation

For each file, provide:

  • The complete and functional code
  • Comments explaining architectural choices
  • Recommended folder structure

Start with the project structure, then implement each layer starting from the data schema.

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 is effective because it structures the request into distinct architectural layers, forcing Claude to produce organized and maintainable code rather than a monolithic file. The explicit specification of business resources and their attributes gives Claude the necessary context to generate coherent relationships and relevant validations. The imposed implementation order (schema → layers → documentation) reproduces the natural workflow of a senior developer, ensuring each layer builds on the previous one.

Use Cases

Create a REST API

Variants

Expected Output

Claude generates a complete REST API with a professional project structure, including all necessary files: data models, routes, controllers, services, authentication and validation middlewares, and Swagger configuration. The code is ready to run after installing dependencies, with clear instructions for startup and required environment variables.

Frequently Asked Questions

Which framework should I ask Claude to use for my REST API?

The choice depends on your ecosystem and needs. For JavaScript/TypeScript, Express remains the most flexible and well-documented, while NestJS offers an opinionated architecture ideal for larger teams. FastAPI (Python) is excellent for APIs requiring high performance and automatic documentation. Django REST Framework suits projects needing a mature ORM and an admin panel. Always specify the framework in your prompt so Claude can adapt conventions, file structure, and complementary libraries.

How do I ask Claude to handle relationships between resources in the API?

Describe the relationships explicitly in your prompt: "A user has many orders (one-to-many), an order contains several products (many-to-many via a junction table)". Ask for nested endpoints like GET /users/:id/orders and specify whether you want lazy loading or eager loading. Claude will generate models with foreign keys, corresponding migrations, and endpoints that respect these relationships with appropriate joins.

Can Claude generate tests for my REST API?

Yes, and it's highly recommended to include them in your prompt. Explicitly ask for unit tests for business logic (services), integration tests for endpoints (with supertest or httpx), and fixtures for test data. Specify your preferred testing framework (Jest, Vitest, pytest) and whether you want a separate test database or mocks. Claude will generate test suites covering happy paths, validation errors, authentication, and edge cases like non-existent resources.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour éviter les limitations de tokens, découpe cette demande en plusieurs prompts : structure + schéma d’abord, puis chaque couche (routes, controllers, etc.) séparément. Ainsi Claude ne tronquera pas les fichiers et tu obtiendras un code complet.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

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.

383
💻DeveloppementIntermediateAll AIs

Implement rate limiting

Protect APIs from abuse

395
💻DeveloppementIntermediateAll AIs

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.

425
💻DeveloppementAdvancedAll AIs

Implement CSP with nonces

Prevent XSS with strict CSP

429