P

Claude Prompt to Create a REST API

Creating a REST API is a fundamental task of modern backend development. Whether you're 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 chosen framework (Express, FastAPI, NestJS, Django REST, Spring Boot) while applying RESTful conventions: appropriate HTTP verbs, correct status codes, pagination, filtering, and versioning. This guide offers optimized prompts to get the most out of Claude in designing and implementing your REST APIs, from rapid prototype to full microservices architecture.

The prompt

Claude

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

Tech stack: [Framework, e.g., Node.js with Express and TypeScript]
Database: [DB, 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 it 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 context needed to generate consistent relationships and relevant validations. The enforced implementation order (schema → layers → documentation) reproduces the natural workflow of a senior developer, ensuring that each layer builds upon the previous one.

Expected result

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

Variants by level

FAQ

Which framework should I ask Claude for my REST API?
The choice depends on your ecosystem and needs. For JavaScript/TypeScript, Express remains the most flexible and documented, while NestJS offers an opinionated architecture ideal for large teams. FastAPI (Python) is excellent for APIs requiring high performance and automatic documentation. Django REST Framework suits projects needing a mature ORM and admin panel. Always specify the framework in your prompt so that Claude adapts conventions, file structure, and complementary libraries.
How to ask Claude to handle relationships between resources in the API?
Explicitly describe the relationships in your prompt: "A user has many orders (one-to-many), an order contains many 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 the desired testing framework (Jest, Vitest, pytest) and whether you want a separate test database or mocks. Claude will generate test suites covering nominal cases, validation errors, authentication, and edge cases like missing resources.

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

Claude Prompt to Create a Sales Funnel

Creating an effective sales funnel is one of the major challenges of digital marketing. Each stage — from the capture page to the email sequence, through the sales page and upsell — must be designed to guide the prospect toward purchase.

Claude Prompt to Create a Social Media Strategy

Social media has become an essential lever for developing brand visibility, generating leads, and building a loyal community. Yet, building a coherent and effective social media strategy remains a complex exercise: you need to analyze your audience, choose the right platforms, define an editorial line, plan content, and measure results. Claude excels at this task thanks to its ability to structure a complete strategic reflection while taking into account multiple variables simultaneously. By providing it with accurate information about your business, your goals, and your target audience, you get a customized social media strategy with an editorial calendar, format recommendations, and adapted KPIs. The AI saves you hours of work by synthesizing industry best practices while tailoring them to your specific context. Whether you are a community manager, entrepreneur, or marketing manager, these prompts will allow you to move from an improvised social presence to a methodical, results-oriented strategy.

Claude Prompt to Create an Editorial Calendar

Creating an editorial calendar is a fundamental step for any successful content strategy. Without structured planning, publications become irregular, topics repeat, and seasonal opportunities are missed.

Claude Prompt to Create an Email Campaign

Creating an effective email campaign requires mastery of many elements: audience segmentation, persuasive writing, sequence structure, send timing, and open rate optimization.

Claude Prompt to Create an FAQ

Creating an effective FAQ is more complex than it seems. It's not just about listing obvious questions, but about anticipating your audience's real queries, structuring answers to be both complete and concise, and optimizing everything for SEO.

Claude Prompt to Create Infographics

Infographics are powerful visual communication tools that transform complex data into clear and engaging graphical representations

Go further

Get new prompts every week

Join our newsletter.