Data Access
Delete
Deleting rows is performed by issuing DELETE
requests.
Delete one row
Deleting one row is done by performing a DELETE
request and providing the filtering condition on the primary key that uniquely identifies the row
curl -X DELETE \
http://localhost:3000/rest/todos?id=eq.10
Deleting multiple rows
Deleting multiple rows is done by performing a DELETE
request and providing the filtering condition
curl -X DELETE \
http://localhost:3000/rest/todos?id=gt.10
Receive the deleted row columns
In some cases, it's desired to receive in the response some columns of the deleted rows.
To achieve this result one must include the Prefer: return=representation
header with the DELETE
request. In almost all cases, this header is used in combination with the select query parameter to avoid fetching all the columns of the deleted row.
curl -X DELETE \
-H 'Prefer: return=representation' \
"http://localhost:3000/rest/todos?id=gt.10&select=id,created_at"
When deleting a single row, in order to receive back a json object representing the row (instead of a json array with a single item) include the Accept: application/vnd.pgrst.object+json
header.
curl -X DELETE \
-H 'Prefer: return=representation' \
-H 'Accept: application/vnd.pgrst.object+json' \
"http://localhost:3000/rest/todos?id=eq.10&select=id,created_at"