The following principles should be considered when extending, creating, or updating endpoints in CoCart
Route | Resource type | Expected data |
---|---|---|
cocart/v2/cart | Cart | A cart object |
cocart/v2/cart/items | Cart Item | A list of cart item objects |
cocart/v2/products | Product | A list of product objects |
cocart/v2/products/1 | Product | A product object |
WP_Error
object.
Error messages should be localized, but do not need to be written with language aimed at customers (clients should use the given error code to create customer-facing notices as needed).
Error codes should have the prefix cocart_
.
cocart/v2/cart/add-item
endpoint which accepts a quantity and product ID, but returns a full cart object, rather than just an updated list of items.
wp_kses_post
.
It is the client’s responsibility to properly escape data that comes from the API, but we should try to avoid returning data that is potentially unsafe.
X-WP-Total
, X-WP-TotalPages
, and Link
to indicate available resources.page
and per_page
to retrieve certain pages.per_page
is 100.200 OK
for successful responses (this is the default response code).201 Created
when creating a resource, for example, adding a new cart item or applying a new coupon.204 No Content
for successful deletes.400 Bad Request
when a required parameter is not set.403 Forbidden
when a request is not allowed, for example, if the provided security nonce is invalid.404 Not Found
if a resource does not exist.409 Conflict
if a resource cannot be updated, for example, if something in the cart is invalid and removed during the request.DELETE
requests, a common pattern in the WordPress REST API is to return the deleted object.
A full list of HTTP status codes can be found here.