Reputation: 992
been playing with Apigility a bit and there is something i do not like. My delete method in an entity mapper looks like:
public function delete($id)
{
$affectedRows = $this->table->delete(
array('userId' => $id)
);
if (0 === $affectedRows) {
throw new DomainException('ID not found', 500);
}
return $affectedRows;
}
And in the matching entity resources i've got:
public function delete($id)
{
$affectedRows = $this->mapper->delete($id);
return new ApiProblem(200, 'Affected rows count ' . $affectedRows);
}
but i think it is not appropiate to call ApiProblem for a 200 code. Is there anything that suits for a success operation?
Upvotes: 2
Views: 885
Reputation: 44326
ApiProblem
should not be used in this case. It should only be returned in case of problems/errors.
Read the answer on StackOverflow here for a reference to how to respond to successful delete operations.
Upvotes: 1
Reputation: 2705
application/problem+json
is NOT proper response for successful operation.
You should return response normally with status code 200 or no response with status code 204.
And you can use ApiProblem when resource is not found.
As side note: domain exception is not suitable for runtime conditions, it generally points at bug in software.
Upvotes: 3