Development Convention

Http Response

Success:

{
   "result":"success",
   "meta":"<Meta Object, like pagination options|Optional>",
   "message":"<success messages|Optional>",
   "data":"<Data Object or Data Arrary|Optional>"
}

failure

{
   "result":"failure",
   "message":"<failure messages|Optional>",
   "data":"<Data Object or Data Arrary|Optional>",
   "errors":"<Extended error message Array or Object |Optional>"
}

Usage

Create or update a resource success

  • status 200
{
  "result": "success",
  "data": {
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }
}
{
  "result": "success",
  "meta":{count:1, total: 1, page: 1, per_page: 10, page_count: 1},
  "data": [{
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }]
}

Normal data

  • status 200
{
  "result": "success",
  "data": {
    "object_id": "a3d182dc-04ba-4fba-96ff-d07580baff2b",
    "property":"value",
    "meta_data": {}
  }
}

Pagination data

  • status 200
{
  "result": "success",
  "data": [
    {
      "object_id": "fb172bdc-3f75-4404-9fd9-7e41d1fcf33a",
      "property": "value",
      "meta_data": {}
    },
    {
      "object_id": "8fd27037-af93-4390-a756-a26cbecff55d",
      "property": "value",
      "meta_data": {}
    },
    {
      "object_id": "ccc9e2f1-c69e-4f3d-afa7-563de5ce7c2b",
      "property": "value",
      "meta_data": {}
    }
  ],
  "meta":{
    "page": 1,
    "last_page": 10,
    "count": 100,
    "current": 10,
    "from": 1,
    "to": 10
  }
}

Create a resource failed

  • status 409: Resource conflict

    {
    "result": "failure",
    "message": "resource exists"
    }

Validation Error Message

  • status 422: Invalid parameter
{
  "result": "failure",
  "message":"Invalid parameter",
  "errors": [
      "Status must be in { \"complete\", \"cancelled\" }"
  ]
}
{
  "result": "failure",
  "message": "Invalid OrgGID provided."
}

Http Status

  • 200 OK - [*] The request has succeeded.
  • 400 INVALID REQUEST - [POST/PUT/PATCH] This response means that server could not understand the request due to invalid syntax.
  • 401 Unauthorized - [*] Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated"
  • 403 Forbidden - [*] The client does not have access rights to the content, i.e. they are unauthorized, so the server is rejecting to give a proper response.
  • 404 NOT FOUND - [*] The server cannot find the requested resource.
  • 405 Method Not Allowed - [*] The request method is known by the server but is not supported by the target resource.
  • 406 Not Acceptable - [*] This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content following the criteria given by the user agent.
  • 409 Conflict - [POST/PUT/PATCH] This response is sent when a request conflicts with the current state of the server
  • 422 Unprocessable entity - [POST/PUT/PATCH] The request was well-formed but was unable to be followed due to semantic errors.
  • 429 Too Many Requests - [*] The user has sent too many requests in a given amount of time ("rate limiting").
  • 500 INTERNAL SERVER ERROR - [*] The server has encountered a situation it doesn't know how to handle.

标签: none

评论已关闭