Example result: Design a REST API for your app
AI-generated example · API Design
Updated

Design a REST API for your app

This prompt helps you design a REST API. You describe the app, its main resources and how auth works, and it lists endpoints with method, path and purpose, with request and response examples.

text-api-design-helper — chatgpt — 56 words

Help me design a REST API.

App: [WHAT IT DOES]
Main resources: [e.g. users, orders, products]
Auth: [JWT / SESSION / NONE]

List endpoints (method, path, purpose), request and response JSON examples for 3 of them, error format, pagination approach and status codes to use. Follow REST conventions and point out anything I may have missed.

Ask for an OpenAPI (YAML) version once the design looks right.

Get a better result

What you will get

A first draft of your API: a table of endpoints with method, path and purpose, sample request and response JSON for three of them, one error format, a pagination plan, the status codes to use and a short list of things you forgot.

Why it works

Naming the resources and the auth type up front stops the model from inventing a generic shop or blog API. Asking for full JSON examples on only three endpoints keeps the answer short enough to read, while still showing the shape every other endpoint will copy. The last line, “point out anything I may have missed”, turns it from a typist into a reviewer.

Common mistake

The endpoints use verbs, like /createOrder and /getUsers.

Fix: Ask it to name resources as plural nouns and let the HTTP method carry the action, so POST /orders creates and GET /users lists.

Also watch for
  • Every list endpoint returns everything at once. Say how big the lists can get, for example “a shop can have 50,000 orders”, and ask for cursor or page based pagination with a default page size.
  • Errors come back in a different shape on each endpoint. Ask for one error object used everywhere, with a machine code, a human message and the field that failed, and make the examples show it.
Try a variation: plan for version 2

Ask how to add a breaking change later without hurting existing clients, and whether a version in the path or in a header suits your app better.

Still not right? Reply with this

Now write this design as an OpenAPI 3 YAML file, with the request and response schemas and the shared error object.

More chat & writing prompts

See all 465 →