diff --git a/readme.md b/readme.md index c1e9a54..47562e2 100644 --- a/readme.md +++ b/readme.md @@ -16,26 +16,156 @@ yarn add formjs-vue2 ## Uses -#### API call -It can be used to make an API call. -```vue +### API call +It is possible to perform API call using formjs with the help of `http.visit()` method. +```vue +``` +However, it's usually easier to use one of formjs's quick shortcut methods. These methods have all the same options as `http.visit()`. + +```vue + +``` + +> Uploading files via put is not supported in Laravel. Instead, make the request via post, including a _method field set to put. This is called form [method spoofing](https://laravel.com/docs/8.x/routing#form-method-spoofing). + +### Data +You may use the `data` option to add data to the request. + +```vue + +``` + +For convenience, the `get()`, `post()` and `put()` methods all accept data as their second argument. + +```vue + +``` + +### API Responses +formjs provides four different callbacks `onSuccess`, `onErrors`, `onError` and `onFinish` to handle the API responses. + +#### onSuccess +It is called when response status is in 200 (success) range. It gets response as callback argument. +```vue + +``` + +#### onErrors +formjs provides dedicated callback to handle validation errors. Any API response return with 422 status will be captured by `onErrors` callback. The validation errors response should be in Laravel's [error response format](https://laravel.com/docs/10.x/validation#validation-error-response-format) +```vue + ``` +#### onError +It is called when the server return response of 400 to 500 status range. +```vue + +``` -#### Form +#### onFinish +It is called everytime when the API call is completed, no matter what the response is. This callback can be used to track the loading state of a API call. ```vue + +``` + +### Custom Headers +The `headers` option allows you to add custom headers to a request. +```vue + +``` + +### Form +The primary use case of formjs is to ease the form handling by reducing amount of boilerplate code needed for form submissions. +```vue