cerenimo/response-messages

dev-main 2023-07-31 08:18 UTC

This package is auto-updated.

Last update: 2024-05-30 01:16:50 UTC


README

composer require cerenimo/response-messages "dev-main" 

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.

  • responseBadRequest($message = null) : Use if the sent request is incorrect.

  • responseConflict($message = null) : Use if a mismatch occurs due to a predetermined rule or version differences on the web server of your request.

  • responsePayloadTooLarge($message = null) : Use if the request entity is much larger than the limits defined by the server.

  • responseTooManyRequests($message = null) : Use if the website exceeded the specified request limit.

  • responseInternalServer($message = null) : Use if a server-side error occurred.

  • responseNotImplemented($message = null) : Use if the server does not support the features required to fulfill the request.