Promptabide Logo
KS

Kabir Singh

@kabir_singh2 months ago

A Prompt That Writes Express Endpoints I Actually Ship

The constraint list that turns a toy endpoint into a production one.

backend
express
typescript
api
Keywords:
express endpoint
validation
transaction
Generated endpoints are usually 80% there and missing exactly the 20% that matters in production. This constraint block closes the gap:

"Write an Express + TypeScript endpoint.

Endpoint: [method] [path]
Purpose: [one sentence]

Non-negotiables:
  • • Validate the body with express-validator; return 422 with field-level errors

  • • Auth via the existing authMiddleware; 401 if absent, 403 if the role is wrong

  • • Wrap DB work in a transaction and roll back on any throw

  • • No secrets or IDs in log lines

  • • Return the shared ResponseHelper envelope, never res.json directly

  • • Paginate any list response, default 20, max 100

  • • Handle the unique-constraint violation explicitly, not as a 500"


  • The last two are the ones I used to fix by hand on every single generated endpoint. Putting them in the prompt cut my review time roughly in half.

    Attachments (1)

    Attachment
    11.3k8

    Generated Outputs (1)

    1 weeks ago
    Claude
    claude-sonnet-4
    Generated Output
    router.post("/orders", authMiddleware, validate(createOrderRules), async (req, res) => {
    const t = await sequelize.transaction()
    try {
    const order = await Order.create({ ...req.body, user_id: req.user.id }, { transaction: t })
    await t.commit()
    return ResponseHelper.success(res, "Order created", order)
    } catch (err) {
    await t.rollback()
    if (err instanceof UniqueConstraintError) {
    return ResponseHelper.validationError(res, "Order reference already exists")
    }
    throw err
    }
    })
    Comments (8)
    No comments yet. Be the first to share your thoughts!
    Top Contributors
    Loading...
    Follow PromptAbide

    New bides, prompt breakdowns and community picks, on whichever feed you already read.

    Trending Tags
    Loading...
    A Prompt That Writes Express Endpoints I Actually Ship | PromptAbide