Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fernandozueet/response-laravel

Library for standardization of error messages and success of api json.
https://github.com/fernandozueet/response-laravel

messages response response-errors response-laravel response-messages

Last synced: 26 days ago
JSON representation

Library for standardization of error messages and success of api json.

Awesome Lists containing this project

README

        

# Response laravel

Library for standardization of error messages and success of api json.

---

## Requirements

- PHP 7.0 or newer;
- Laravel 5.8 or newer;

---

## Installation

```bash
composer require fernandozueet/response-laravel
```

---

Response status 204:

status 204

```php
return respond_empty();
```

---

Response success:

status 200

```php
return respond_success('Record changed successfully.');

//or

//create translation file
return respond_success('filex.record_success');
```

```json
{
"status": "success",
"message": "Record changed successfully."
}
```

---

Response success and included data:

status 200

```php
return respond_success('Record changed successfully', [ 'type' => 1 ]);
```

```json
{
"status": "success",
"message": "Record changed successfully.",
"data": {
"type": 1
}
}
```

---

Response created:

status 201

```php
return respond_created('Record created successfully.');
```

```json
{
"status": "success",
"message": "Record created successfully."
}
```

---

Response created and included data:

status 201

```php
return respond_created('Record created successfully.', [ 'type' => 1 ]);
```

```json
{
"status": "success",
"message": "Record created successfully.",
"data": {
"type": 1
}
}
```

---

Response error:

status 400

```php
return respond_error('Error while changing registry.');
```

```json
{
"status": "error",
"message": "Error while changing registry."
}
```

---

Response error and included data:

status 400

```php
return respond_error('Error while changing registry.', [ 'type' => 1 ]);
```

```json
{
"status": "error",
"message": "Error while changing registry.",
"data": {
"type": 1
}
}
```

---

Response error:

status 401

```php
return respond_unauthorized();
```

```json
{
"status": "error",
"message": "Unauthenticated."
}
```

---

## Contributing

Please see [CONTRIBUTING](https://github.com/FernandoZueet/response-laravel/graphs/contributors) for details.

## Security

If you discover security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Fernando Zueet](https://github.com/FernandoZueet)

## License

The package is licensed under the MIT license. See [License File](LICENSE.md) for more information.