PRACTICAL FIELD GUIDE
DELETE returned 204 No Content and response.json() threw an error
A 204 response indicates successful completion without a response body. Calling a JSON parser unconditionally can turn a successful deletion into a client-side error.
MCPBackend editorial team · · Examples are illustrative
The short answer
If a DELETE returns 204 and your code then throws "Unexpected end of JSON input", the delete succeeded and your parser failed. 204 No Content means the server handled the request and has nothing to send back. There is no body, so response.json() throws on the empty string. Branch on the status first and only parse a body when one exists.
const res = await fetch(`${base}/v1/${projectId}/db/tasks/${id}`, {
method: "DELETE",
headers: { authorization: `Bearer ${token}` },
});
if (res.status === 204) {
removeFromList(id); // success, no body
} else {
const { error } = await res.json(); // errors do carry JSON: { error: { message, code } }
showError(error.message);
}What a 204 from MCPBackend does and does not tell you
MCPBackend answers DELETE /v1/{projectId}/db/{table}/{id} with 204 once the caller is allowed to delete from that table. The delete statement is scoped to the caller's rows when owner row security applies, and the API does not check how many rows it removed. A 204 therefore means "no row with this ID is visible to you any more", not "a row was just removed". Deleting an ID that never existed, or one owned by someone else, also returns 204.
If you need proof that a specific row was removed, GET it before the delete or count rows afterwards. Permission problems still fail loudly: a key without delete permission or a table that does not allow the caller returns an error with JSON before anything runs.
A successful DELETE also sends a deleted webhook to any matching subscription, with only the primary key in data. That event is sent even when no row with that ID existed, so a webhook consumer should remove items idempotently.
A request helper that never chokes on an empty body
Rather than special-casing every DELETE, read the body as text once and parse it only when there is something to parse. This handles 204, an empty 200 and JSON errors with one code path.
async function api(path, init = {}) {
const res = await fetch(`${base}/v1/${projectId}${path}`, {
...init,
headers: { authorization: `Bearer ${token}`, "content-type": "application/json", ...init.headers },
});
const text = await res.text(); // "" for a 204
const body = text ? JSON.parse(text) : null;
if (!res.ok) throw new Error(body?.error?.message ?? `HTTP ${res.status}`);
return body; // null after a DELETE
}
await api(`/db/tasks/${id}`, { method: "DELETE" }); // resolves to null, no throwShould DELETE return 200 or 204?
Both are correct HTTP. Use 200 when the response carries something useful, such as the deleted row or a status object. Use 204 when there is nothing to say beyond success. 202 Accepted fits a delete that is queued and will finish later. MCPBackend returns 204 for DELETE and 200 with the row for PATCH, so a client that wants the old values should read the row before deleting it.
Put it into practice
- Check the response status before parsing.
- For a successful 204, update local UI state without expecting a returned row.
- For non-success responses, read the documented error payload and preserve the record in the UI until resolved.
What this looks like
ILLUSTRATIVE EXAMPLE
The server deletes a disposable task and returns 204. The UI then throws while parsing an empty body and misleadingly reports failure.
A boundary to keep clear
Do not repeat the delete merely because the client parser failed. Check the operation's actual result first.
Read next
MCPBackend context
Use get_project_api or the dashboard's generated OpenAPI contract for your project's exact data-plane routes. Machine keys and end-user tokens have different access models. Treat error status and JSON code together, keep credentials out of URLs, and test against disposable records before changing real data.
Take the next step
Inspect the current project contract, try the change with disposable data, and verify the result through the same credentials your app will use. Record the expected response and one denied-access case before release.
Frequently asked questions
Why does response.json() throw after a successful DELETE?
Because a 204 response has an empty body by definition, and JSON.parse of an empty string throws. Check res.status === 204 (or res.ok with a content-length of 0) before calling res.json().
Should a REST API return 200 or 204 for DELETE?
Both are valid HTTP. 200 is used when the server returns something, such as the deleted row; 204 when it returns nothing. MCPBackend returns 204, so clients should not expect the deleted row back.
Does a 204 mean the record existed?
Not on MCPBackend. A 204 means the delete ran with your permissions. If the ID did not exist or was not visible to you, nothing was removed and you still get 204.
Sources and further reading
These references explain the underlying protocols and design principles. For supported MCPBackend operations and exact request shapes, inspect your project’s generated API contract.