状态码和响应
REST 响应
每个web API调用返回HTTP状态代码和响应有效载荷。当一个错误occcurs,响应体也返回一个错误消息。
HTTP 状态码
每个web API调用返回一个反映请求结果的HTTP状态代码:
HTTP代码 | 意义 |
---|---|
200 | Success |
400 | Bad Request |
401 | Unauthorized |
403 | Forbidden |
404 | Not found |
405 | Not allowed |
406 | Not acceptable |
500 | System Errors |
响应 payload
示例, GET /V1/customers/:customerId
调用返回以下有效载荷:
{
"customers": {
"customer": {
"email": "[email protected]",
"firstname": "John",
"lastname": "Doe"
},
"addresses": [
{
"defaultShipping": true,
"defaultBilling": true,
"firstname": "John",
"lastname": "Doe",
"region": {
"regionCode": "CA",
"region": "California",
"regionId": 12
},
"postcode": "90001",
"street": ["Zoe Ave"],
"city": "Los Angeles",
"telephone": "555-000-00-00",
"countryId": "US"
}
]
}
}
Error 格式
参数 | 描述 |
---|---|
code |
表示错误的状态代码。 |
message |
解释错误的消息。 |
parameters |
可选。用于生成客户端的或本地化错误消息的属性数组。 |
例子: PUT V1/products/:sku
.
{
"message": "Invalid product data: %1",
"parameters": [
"Invalid attribute set entity type"
]
}