From db0a2c63be61b7ad964c036e6a10109a4bf16355 Mon Sep 17 00:00:00 2001 From: Muhammad Harits Syaifulloh Date: Sat, 5 Oct 2019 09:28:04 +0700 Subject: [PATCH 1/3] New format for validation problems. --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ddc81a7..5aa5edb 100644 --- a/README.md +++ b/README.md @@ -99,15 +99,19 @@ The following example is format usually used for failed response with status cod } ``` -For returning multiple validation problems, here's the example: +For returning multiple validation problems, it **MUST** return error messages inside an array. Inside the `errors` array **MUST** contain the following element: +- `key` : taken from request body's property that doesn't pass the validation +- `value`: is the validation error message + +Here's the example for multiple validation problems: ``` { "success": false, "error-code": null, /* or optional error payload, eg: 3001, 3002, etc. */ "errors": [ - "The email must be a valid email", - "The password must be at least 6 chaarcters", - "The phone number is already used" + "email": "The email must be a valid email", + "password": "The password must be at least 6 chaarcters", + "phone": "The phone number is already used" ], "message": "Error xyz has occurred" } From 4cf0a40d945ca0a76134076687c824a4ea57ff61 Mon Sep 17 00:00:00 2001 From: Muhammad Harits Syaifulloh Date: Sun, 6 Oct 2019 22:29:32 +0700 Subject: [PATCH 2/3] HTTP response code --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 5aa5edb..80279fa 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,51 @@ Here's the example for multiple validation problems: ``` ## HTTP Response Code +Http response status code indicate whether a specific HTTP request hasbeen successfully completed. There are 3 types of response code usually used: +- Successful response (`2xx`) +- Client errors (`4xx`) +- Server errors (`5xx`) + +### Successful Responses (`2xx`) +**200 OK** + +The request has succeeded. The meaning of the success depends on the HTTP method: +- `GET`: The resource has been fetched and is transmitted in the message body. +- `PUT or POST`: The resource describing the result of the action is transmitted in the message body. + +**201 Created** + +The request has succeeded and a new resource has been created as a result. This is typically the response sent after `POST` requests, or some `PUT` requests. + +### Client Error Responses (`4xx`) +**400 Bad Request** + +The server could not understand the request due to invalid syntax. + +**401 Unauthorized** + +Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. + +**404 Not Found** + +The server couldn't find requested resource. This can be the URL / endpoint or the data that client looking for is not exists. + +**405 Method Not Allowed** + +The request method is known by the server, but has been disabled and cannot be used. For example: +> An endpoint `/users/1` must be requested using `GET` HTTP verb, but we access it using `POST` HTTP verb. + +According to the case above, the server will return a response with the `405` status code. + +### Server Error Response (`5xx`) +**500 Internal Server Error** + +This means that the server has encountered a situation it doesn't know how to handle. For example when a failure occurred in deleting data. + +**502 Bad Gateway** + +This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response. Or in short, when our server is down. + ## Error Code ## Panduan Kontribusi From 78e0738010245051921de828d50b48e29d642530 Mon Sep 17 00:00:00 2001 From: Muhammad Harits Syaifulloh Date: Sun, 6 Oct 2019 22:31:25 +0700 Subject: [PATCH 3/3] HTTP response code --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80279fa..a76b06a 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Here's the example for multiple validation problems: ``` ## HTTP Response Code -Http response status code indicate whether a specific HTTP request hasbeen successfully completed. There are 3 types of response code usually used: +HTTP response status code indicate whether a specific HTTP request hasbeen successfully completed. There are 3 types of response code usually used: - Successful response (`2xx`) - Client errors (`4xx`) - Server errors (`5xx`)