Order Shorthand
Mike.robski (Talk | contribs) |
Mike.robski (Talk | contribs) m (1 revision) |
Revision as of 00:58, 17 February 2013
/order
A shorthand that allows a user to access directly the current open order with the appropriate OwnerId.
Contents |
Request Headers
- Cookie
- Required. Any call trying to use the shorthand notation has to have a valid OwnerId cookie set, with the exception of calls that will create a new order implicitly. A valid Set-Cookie header is returned with the response of either implicit or explicit order creation calls.
Order Shorthand
Using /order
will try to find an order with status new that is associated with the OwnerId specified in the cookie header sent with the request. The value of the cookie may be set by either explicit or implicit order creation.
Available Methods and Child Resources
The shorthand supports all the methods that are available when using the /orders/{orderId}
notation and all of the order's child resources are also accessible using the shortcut. A GET call to the order shorthand itself will include an alternate link to the explicit URL of the order in the hypermedia section. If an order is submitted using the shorthand URL, a Location header containing the explicit location of the order will be returned with a successful response for future reference.
Implicit Order Creation
If there is no current order associated with the active user, that is not submitted, a PUT or POST call to a child resource will implicitly create a new order for the user and will populate the data of the actual call to the new order. The final response of the implicitly created order will contain additional Set-Cookie header as described below. A GET or OPTIONS call to a non-existing order will not create it implicitly, but will return response with 404 status code.
Response Headers
- Set-Cookie
- If an order is created implicitly while accessing a child resource, the final response will include a Set-Cookie header containing an OwnerId identifier, in a similar way to explicit creation of an order using POST /orders. The cookie will be used to identify the end user, if no existing account is associated with the order, and to find which is the currently open order associated with the end client.
Additional Status Code
In addition to the response status codes that can be returned by various /orders/{orderId}
calls, the order shorthand may also return:
- 409 Conflict
- There is already a new order associated with the same OwnerId and a second order cannot be created until the existing one is either submitted or deleted.
Examples
Implicit Creation
Request
PUT /order/account Content-Type: application/json; charset=UTF-8 Authorization: {Base64-encoded username & password string} { "currency": "USD", "language": "en-US" }
Response
200 OK Set-Cookie: OwnerId=4d84cd13-bbb3-46ba-a40c-8988351e3681; Path=/order Set-Cookie: OwnerId=4d84cd13-bbb3-46ba-a40c-8988351e3681; Path=/orders
Alternate Hypermedia
Request
GET /order Authorization: {Base64-encoded username & password string} Cookie: OwnerId=4d84cd13-bbb3-46ba-a40c-8988351e3681; Path=/order
Response
200 OK Content-Type: application/json; charset=UTF-8 { "order": { "OwnerId": "4d84cd13-bbb3-46ba-a40c-8988351e3681" }, "links": { "self": {"href": "https://api.hostway.com/order/", "rel": "self"}, "alternate": {"href": "https://api.hostway.com/orders/{orderId}/", "rel": "alternate"} } }
Accessing a Child Resource
Request
GET /order/product/{productId} Authorization: {Base64-encoded username & password string} Cookie: OwnerId=4d84cd13-bbb3-46ba-a40c-8988351e3681; Path=/order
Response
200 OK Content-Type: application/json; charset=UTF-8 { "status": "new", "services": "https://api.hostway.com/order/product/{productId}/services", "offering": "https://api.hostway.com/productSpecifications/{productSpecId}/offerings/{offering}", "links": [ {"href": "https://api.hostway.com/order/product/{productId}/", "rel": "self"} ] }
See also