Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response Format #7

Open
ryanking13 opened this issue Nov 13, 2017 · 0 comments
Open

Response Format #7

ryanking13 opened this issue Nov 13, 2017 · 0 comments

Comments

@ryanking13
Copy link
Member

ryanking13 commented Nov 13, 2017

Response Format

{
  "resultcode": 200 ( for successful requests ) / 4xx or 5xx ( for failed requests)
  "success" : true / false,
  "message" : "Response message",
  "data" : response data ( if none - [])
}
# use send_response() function for sending response

var send_response = require("../general/response_manager.js").send_response

return send_response(res, 400, "Message")

    {
      "resultcode": 400,
      "success": false,
      "message": "Message",
      "data": [],
    }

return send_response(res, 200, "Message", data)

    {
      "resultcode": 200,
      "success": true,
      "message": "Message",
      "data": data,
    }



Common Responses

Success

  • Returning Data
{
  "resultcode" : 200,
  "success" : true,
  "message" : "",
  "data": [{"some": "data"}],
}

  • Not returning Data
{
  "resultcode" : 200,
  "success" : true,
  "message" : "",
  "data": [],
}

Fail

  • Lacking parameters
{
  "resultcode" : 400,
  "success" : false,
  "message" : "Parameters not given",
  "data": [],
}

  • User authentication fail
{
  "resultcode" : 401,
  "success" : false,
  "message" : "User auth fail",
  "data": [],
}

  • Internal server error
{
  "resultcode" : 500,
  "success" : false,
  "message" : "Internal server error",
  "data": [],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant