Download the PHP package dragon-code/api-response without Composer

On this page you can find all versions of the php package dragon-code/api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package api-response

API Response

API Response

Stable Version Unstable Version Total Downloads

Package for standardizing the responses from the API of your Symfony based applications.

Getting Started

Upgrade guides

[ to top ]

Installation

To get the latest version of API Response, simply require the project using Composer:

This command will automatically install the latest version of the package for your environment.

Instead, you may of course manually update your require block and run composer update if you so choose:

Alright! Use api_response() helper.

Compatibility table

Package version PHP min version Symfony version Support Links
^9.0 7.2.5 ^4.0, ^5.0, ^6.0 Supported Upgrade guide
^8.0 7.2.5 ^4.0, ^5.0 Not Supported Upgrade guide
^7.0 7.2.5 ^4.0, ^5.0 Not Supported Upgrade guide
^6.0 7.3 ^4.0, ^5.0 Not Supported Upgrade guide
^5.0 7.1.3 ^4.0, ^5.0 Not Supported ---
^4.4.1 5.6.9 ^3.0, ^4.0, ^5.0 Not Supported ---
^4.0 5.6.9 ^3.0, ^4.0 Not Supported ---

[ to top ]

Using

Use with data key

as NULL with code:

return with code 304:

[ to top ]

as integer with default code:

return with code 200:

[ to top ]

as string with default code:

return with code 200:

[ to top ]

as string with code:

return with code 400:

[ to top ]

as integer with code:

return with code 400:

[ to top ]

as array:

[ to top ]

as error

return with code 400:

[ to top ]

as success

return with code 200:

If the first parameter is a number, then the decryption of the error by code will be return. In other cases, the value of the passed variable will be return.

[ to top ]

with additional content

return with code 200:

return with code 400:

return with code 200:

return with code 400:

[ to top ]

Use without data key

Since the goal of the package is to unify all the answers, we moved the variable definitions into a static function. So, for example, to enable or disable wrapping content in the data key, you need to call the wrapped or withoutWrap method:

as NULL with code and without data key:

return with code 304:

[ to top ]

as integer with default code and without data key:

return with code 200:

[ to top ]

as string with default code and without data key:

return with code 200:

[ to top ]

as string with code and without data key:

return with code 400:

[ to top ]

as integer with code and without data key:

return with code 400:

[ to top ]

as array and without data key:

as error and without data key

return with code 400:

[ to top ]

as success and without data key

return with code 200:

If the first parameter is a number, then the decryption of the error by code will be return. In other cases, the value of the passed variable will be return.

[ to top ]

with additional content and without data key:

return with code 200:

return with code 400:

return with code 200:

return with code 400:

[ to top ]

No extra data

In some cases, when returning answers, you must also give additional data. Such as stack trace, for example.

To prevent this data from getting in response to production, you can globally set a label to show or hide this data:

Now all responses will not contain the additional data being passed.

For example:

return with code 200:

return with code 400:

Server Errors

Note: The $with parameter is also responsible for displaying server-side error messages.

In this case, Http errors will be displayed without masking.

For example:

return with code 500:

and

return with code 500:

return with if code >=400 and < 500:

[ to top ]

Returning exception instances

return with code 405:

return with code 408:

return with code 400:

return with code 408:

You can also add additional data:

return with code 405:

[ to top ]

Best practice use with the Laravel and Lumen Frameworks

If you use the Laravel or Lumen framework, you can update the extends in the app\Exceptions\Handler.php file depending on your application version and needs:

Version \ Type API + WEB Only API
9.x DragonCode\ApiResponse\Exceptions\Laravel\Nine\Handler as ExceptionHandler DragonCode\ApiResponse\Exceptions\Laravel\Nine\ApiHandler as ExceptionHandler
8.x DragonCode\ApiResponse\Exceptions\Laravel\Eight\Handler as ExceptionHandler DragonCode\ApiResponse\Exceptions\Laravel\Eight\ApiHandler as ExceptionHandler
7.x DragonCode\ApiResponse\Exceptions\Laravel\Seven\Handler as ExceptionHandler DragonCode\ApiResponse\Exceptions\Laravel\Seven\ApiHandler as ExceptionHandler

If you did not add anything to this file, then delete everything properties and methods.

For example, as a result, a clean file will look like this:

More examples:

[ to top ]

Json Resources

Now, if you pass a resource object or validator object, it will also be rendered beautifully:

return with code 200:

If Response::withoutWrap()

If Response::withoutWith()

If Response::withoutWith() and Response::withoutWrap()

[ to top ]

Validation

If success:

If failed:

[ to top ]

License

This package is licensed under the MIT License.

[ to top ]


All versions of api-response with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
dragon-code/contracts Version ^2.2
dragon-code/support Version ^6.0
symfony/http-foundation Version ^4.0 || ^5.0 || ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dragon-code/api-response contains the following files

Loading the files please wait ....