-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Diogo Castro edited this page May 13, 2016
·
6 revisions
- 200 OK
- 201 Created
- 302 Found
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found
- 500 Internal Server Error
- Misc
JSendOk()
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"status" : "success",
"data" : null
}
JSendOk(article)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"status" : "success",
"data" : {
"title" : ""
}
}
JSendCreated("http://localhost/articles/5", article)
JSendCreatedAtRoute("GetArticle", new {id = 5}, article)
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Location: http://localhost/articles/5
{
"status" : "success",
"data" : {
"title" : ""
}
}
JSendRedirect("http://localhost/articles/5")
JSendRedirectToRoute("GetArticle", new {id = 5})
HTTP/1.1 302 Found
Content-Type: application/json; charset=utf-8
Location: http://localhost/articles/5
{
"status" : "success",
"data" : null
}
JSendBadRequest(reason)
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"status" : "fail",
"data" : "reason"
}
JSendBadRequest(ModelState)
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"status" : "fail",
"data" : {
"article.Title" : "The Title field is required."
}
}
JSendUnauthorized(new AuthenticationHeaderValue("challenge-scheme"))
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
WWW-Authenticate: challenge-scheme
{
"status" : "fail",
"data" : "Authorization has been denied for this request."
}
JSendNotFound()
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8
{
"status" : "fail",
"data" : "The requested resource could not be found."
}
JSendNotFound(reason)
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8
{
"status" : "fail",
"data" : "reason"
}
JSendInternalServerError(string message, int? errorCode = null, object data = null)
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
{
"status" : "error",
"message" : "the server failed because of reasons",
"code": 92,
"data" : "placeholder for additional data"
}
JSendInternalServerError(Exception ex, string message = null, int? errorCode = null, object data = null)
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
{
"status" : "error",
"message" : "custom message or exception message if none is provided",
"code": 92,
"data" : "additional data or exception's stack trace if none is provided"
}
-
JSend<TResponse>(HttpStatusCode, TResponse) where TResponse : IJSendResponse
- creates an arbitrary JSend response -
JSendSuccess(HttpStatusCode, object)
- creates an arbitrary "success" response -
JSendFail(HttpStatusCode, object)
- creates an arbitrary "fail" response -
JSendError(HttpStatusCode, string, int, object)
- creates an arbitrary "error" response