Guides / API design

HTTP methods

Mock POST, PUT, PATCH, and DELETE Workflows

Build a static CRUD simulation with editable request examples, configured responses, dynamic ids, deliberate status choices, and frontend request helpers.

Mockport Team · Updated September 28, 2026 · 16 min read

What you’ll build

  • POST, PUT, PATCH, and DELETE route definitions.
  • Dynamic ids and editable request examples.
  • Correct 201, 200, and 204 response handling.
  • Read-only test results separate from editable mock payloads.

01

Plan a static CRUD contract

Create a user-workflows project and reserve one route for each method. Mockport supports GET, POST, PUT, PATCH, and DELETE with configured static responses and selected statuses.

These endpoints do not maintain a database. They exercise frontend forms, payloads, success messages, and failure handling against repeatable responses.

  • POST /v1/users → 201 Created
  • PUT /v1/users/:id → 200 OK
  • PATCH /v1/users/:id → 200 OK
  • DELETE /v1/users/:id → 204 No Content
Practical note

The test response is proof of the configured contract, not evidence that a record was persisted.

02

Create a user with POST

Use an editable request example containing the fields the creation form owns. Configure 201 Created and return a complete static user with an invented server-style id.

Serialize the form, set JSON content headers, and check the response status before reading the created fixture.

create-user.ts
const API_URL = import.meta.env.VITE_API_URL;

export type User = {
  id: string;
  name: string;
  email: string;
  role: "member" | "editor";
  active: boolean;
};

export async function createUser(input: {
  name: string;
  email: string;
}): Promise<User> {
  const response = await fetch(`${API_URL}/v1/users`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(input),
  });

  if (response.status !== 201) throw new Error("CREATE_FAILED");
  return response.json() as Promise<User>;
}

03

Replace a resource with PUT

Configure PUT /v1/users/:id for a full replacement. Include every editable field in the request example because omission in a replacement contract differs from leaving a field unchanged.

Resolve usr_123 into the dynamic path and return 200 OK with the complete replacement fixture. This helps verify that the form submits the full intended resource shape.

put-request.json
{
  "name": "Alex Johnson",
  "email": "alex@acme.dev",
  "role": "member",
  "active": true
}
Practical note

Use PUT for a replacement representation and PATCH for partial changes, following your backend’s documented contract.

04

Apply a partial update with PATCH

Configure PATCH /v1/users/:id with an example containing only changed fields. The static response can still return the complete user so the frontend refreshes its local view.

Restrict partial updates to fields your product permits. A mock contract should clarify the intended surface rather than widen it accidentally.

patch-user.ts
export async function updateUser(
  id: string,
  changes: Partial<Pick<User, "name" | "role" | "active">>
): Promise<User> {
  const response = await fetch(
    `${API_URL}/v1/users/${encodeURIComponent(id)}`,
    {
      method: "PATCH",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(changes),
    }
  );

  if (!response.ok) throw new Error("UPDATE_FAILED");
  return response.json() as Promise<User>;
}

05

Delete with 204 No Content

Configure DELETE /v1/users/:id and select 204 No Content. Leave the response body empty. This verifies destructive confirmation and handling of a bodyless response.

After success, update local presentation deliberately: remove the row and move focus to a stable location. Do not call response.json() on a 204 response.

delete-user.ts
export async function deleteUser(id: string): Promise<void> {
  const response = await fetch(
    `${API_URL}/v1/users/${encodeURIComponent(id)}`,
    { method: "DELETE" }
  );

  if (response.status !== 204) throw new Error("DELETE_FAILED");
}

06

Choose statuses and verify test responses

Use 201 for successful creation, 200 when PUT or PATCH returns JSON, and 204 when DELETE returns nothing. Add separate scenario routes for validation or missing-resource outcomes.

Use Test route before connecting the frontend. Confirm method, resolved path, selected status, headers, cookies, and JSON shape against the contract.

POST201 CreatedParse created-user JSON
PUT200 OKParse replacement JSON
PATCH200 OKParse updated-user JSON
DELETE204 No ContentDo not parse a body

Keep the contract predictable, then keep building.

Your CRUD surface now exercises frontend request shapes while remaining intentionally static. Clear method semantics, dynamic ids, and correct status handling let the team build without implying persistence.

Put your next endpoint online in minutes.

Start a 14-day trial. Team workspaces are $9/month with 5 project domains, 15 routes per project, and up to 5 seats.

Start free trial →

Related guides