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

New format for validation problems #9

Merged
merged 3 commits into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,70 @@ 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"
}
```

## 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