- Use specific format for a request. i.e. a collection containing Operation, Property path, Value. This explicitly tells api that which properties are to be edited and what operation should be performed
- Some times people may choose to go with key-value pairs of Property name & Value considering that operation will always be an update operation.
PATCH /api/v1/departments/15
Basic rules:
- You must use HTTP PATCH method for update a resource.
- End point should be single (if not exceptional scenario e.g. Bulk update - but strongly avoid this)
- Proper http response codes must be returned
- Do not add parameters to api, use body instead. Exposing data in url is a risk.
Http response codes to return
HTTP Code | When to return |
---|---|
200 - OK | When api updates a complete resource successfully. |
400 - Bad request | When api fails to update a resource because request sent by client in either invalid or incomplete. E.g. Request does not have values for mandatory properties or alphabets are sent in place of numeric values. |
404 - Not found | When resource you are looking for does not exist |
No comments:
Post a Comment