sametcoban11 / response-package

It standardizes response messages for Laravel and Lumen.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Response Messages

 composer require ceren-ozkurt/response-messages 

The ResponseTrait is a trait used to standardize the HTTP response messages in Laravel and Lumen. You can install it using the composer command mentioned above. To use it in your class, add the following line with the "use" keyword:

use CerenOzkurt\ResponseMessages\ResponseTrait;

class YourClass {

use ResponseTrait;
// ...
}

Inside your function, you can use it as follows:

return $this->responseData(['message' => $message]);

Response / 200 OK

{
    "result": true,
    "data": {
        "message": {
            "id": 372,
            "role": "user",
            "message": "Hi",
            "end_conversation": 0,
            "created_time": "2023-05-30T09:28:01.000000Z",
            "conversation_completion_count": "0.60",
            "word_count": 1
        }
    }
}



The package provides the following functions:
  • responseData($data, $message = null) : Use if the request is successful and data is wanted to be returned.

  • responseSuccess($message = null) : Use if the request is successful.

  • responseError($message = null, $status = 500) : Use if the request is error.

  • responseValidation($validation) : Use if there is a validation error.

  • responseDataNotFound($data_name = null) : Use if not found error.

  • responseForbidden($message = null) : Use in forbidden error.

  • responseUnauthorized($message = null) : Use in unauthorized error.

  • responseTryCatch($message = null, $status = 500) : Use in try-catch error.

  • responseDataCount($data) : Use if the data need count information.

About

It standardizes response messages for Laravel and Lumen.


Languages

Language:PHP 100.0%