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:
- Layered architecture (routes → controllers → services → repositories)
- Full CRUD endpoints for each resource with appropriate HTTP verbs
- Input validation with schemas (Zod or Joi)
- Centralized error handling with standard HTTP codes
- Pagination, sorting, and filtering on list endpoints
- JWT authentication with route protection middleware
- Relationships between resources with nested endpoints
- 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
Answer 3 questions and Léa tailors the prompt to your situation.
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
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.
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
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.
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.
Create a Python Automation Script
Create a professional Python automation script with CLI configuration, structured logging, error handling, and tests.
Analyze and Optimize Algorithmic Complexity
Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.