All Projects → mlanin → Laravel Api Debugger

mlanin / Laravel Api Debugger

Licence: mit
Easy debug for your JSON API.

Projects that are alternatives of or similar to Laravel Api Debugger

Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (+56%)
Mutual labels:  api, rest, debug
Lumen Microservice
Lumen on Docker - Skeleton project with Nginx, MySQL & PHP 7 | Aws ECS, Google Kubernates, Azure Container Engine
Stars: ✭ 183 (+4.57%)
Mutual labels:  api, rest, laravel
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (-39.43%)
Mutual labels:  api, rest, laravel
Jikan Rest
The REST API for Jikan
Stars: ✭ 200 (+14.29%)
Mutual labels:  api, rest, laravel
Dreamfactory
DreamFactory API Management Platform
Stars: ✭ 1,148 (+556%)
Mutual labels:  api, rest, laravel
Laravel Api Boilerplate Jwt
A Laravel 5.8 API Boilerplate to create a ready-to-use REST API in seconds.
Stars: ✭ 1,155 (+560%)
Mutual labels:  api, rest, laravel
Vue Api Query
💎 Elegant and simple way to build requests for REST API
Stars: ✭ 1,528 (+773.14%)
Mutual labels:  api, rest, laravel
Flama
🔥 Fire up your API with this flamethrower
Stars: ✭ 161 (-8%)
Mutual labels:  api, rest
Jda
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Stars: ✭ 2,598 (+1384.57%)
Mutual labels:  api, rest
Axios Actions
Bundle endpoints as callable, reusable services
Stars: ✭ 172 (-1.71%)
Mutual labels:  api, rest
Api Diff
A command line tool for diffing json rest APIs
Stars: ✭ 164 (-6.29%)
Mutual labels:  api, rest
Restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
Stars: ✭ 162 (-7.43%)
Mutual labels:  api, rest
Restful Api With Laravel Definitive Guide
Repository with the base code for the course "RESTful API with Laravel - Definitive-Guide"
Stars: ✭ 156 (-10.86%)
Mutual labels:  api, laravel
Fastapi Crudrouter
A dynamic FastAPI router that automatically creates CRUD routes for your models
Stars: ✭ 159 (-9.14%)
Mutual labels:  api, rest
Restinstance
Robot Framework library for RESTful JSON APIs
Stars: ✭ 157 (-10.29%)
Mutual labels:  api, rest
Mono
Minimalist Framework on top of Express.js
Stars: ✭ 163 (-6.86%)
Mutual labels:  api, rest
Middleware Acl
middleware-acl Access Control Library RBAC casbin
Stars: ✭ 155 (-11.43%)
Mutual labels:  api, rest
Examples
Examples of Mock Service Worker usage with various frameworks and libraries.
Stars: ✭ 163 (-6.86%)
Mutual labels:  api, rest
Roastapp
Laravel学院 Roast 应用源码
Stars: ✭ 164 (-6.29%)
Mutual labels:  api, laravel
Thehive
TheHive: a Scalable, Open Source and Free Security Incident Response Platform
Stars: ✭ 2,300 (+1214.29%)
Mutual labels:  api, rest

Laravel-API-Debugger

Travis

Easily debug your JSON API.

When you are developing JSON API sometimes you need to debug it, but if you will use dd() or var_dump() you will break the output that will affect every client that is working with your API at the moment. Debugger is made to provide you with all your debug information and not corrupt the output.

{
  "posts": [
    {
      "id": 1,
      "title": "Title 1",
      "body": "Body 1"
    },
    {
      "id": 2,
      "title": "Title 2",
      "body": "Body 2"
    }
  ],
  "meta": {
    "total": 2
  },
  "debug": {
    "database": {
      "total": 2,
      "items": [
        {
          "connection": "accounts",
          "query": "select * from `users` where `email` = '[email protected]' limit 1;",
          "time": 0.38
        },
        {
          "connection": "posts",
          "query": "select * from `posts` where `author` = '1';",
          "time": 1.34
        }
      ]
    },
    "dump": [
      "foo",
      [
        1,
        2,
        "bar"
      ]
    ]
  }
}

Installation

This help is for Laravel 5.4 only. Readme for earlier versions can be found in the relevant branches of this repo.

PHP >=5.5.9+ or HHVM 3.3+, Composer and Laravel 5.4+ are required.

To get the latest version of Laravel Laravel-API-Debugger, simply add the following line to the require block of your composer.json file.

For PHP >= 7.1:

"lanin/laravel-api-debugger": "^4.0"

For PHP < 7.1:

"lanin/laravel-api-debugger": "^3.0"

You'll then need to run composer install or composer update to download it and have the autoloader updated.

Once Laravel-API-Debugger is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.

For Laravel 5.4

Lanin\Laravel\ApiDebugger\ServiceProvider::class,

Also you can register a Facade for easier access to the Debugger methods.

For Laravel 5.4

'Debugger' => Lanin\Laravel\ApiDebugger\Facade::class,

For Laravel 5.5 package supports package discovery feature.

Json response

Before extension will populate your answer it will try to distinguish if it is a json response. It will do it by validating if it is a JsonResponse instance. The best way to do it is to return response()->json(); in your controller's method.

Also please be careful with what you return. As if your answer will not be wrapped in any kind of data attribute (pages in the example above), frontend could be damaged because of waiting the particular set of attributes but it will return extra debug one.

So the best way to return your responses is like this

$data = [
    'foo' => 'bar',
    'baz' => 1,
];

return response()->json([
    'data' => [
        'foo' => 'bar',
        'baz' => 1,
    ],
]);

For more info about better practices in JSON APIs you can find here http://jsonapi.org/

Debugging

Debugger's two main tasks are to dump variables and collect anny additional info about your request.

Var dump

Debugger provides you with the easy way to dump any variable you want right in your JSON answer. This functionality sometimes very handy when you have to urgently debug your production environment.

$foo = 'foo';
$bar = [1, 2, 'bar'];

// As a helper
lad($foo, $bar);

// or as a facade
\Debugger::dump($foo, $bar);

You can simultaneously dump as many vars as you want and they will appear in the answer.

Note! Of course it it not the best way do debug your production environment, but sometimes it is the only way. So be careful with this, because everyone will see your output, but at least debug will not break your clients.

Collecting data

Note! By default Debugger will collect data ONLY when you set APP_DEBUG=true. So you don't have to worry that someone will see your system data on production.

All available collections can be found in api-debugger.php config that you can publish and update as you wish.

QueriesCollection

This collections listens to all queries events and logs them in connections, query, time structure.

CacheCollection

It can show you cache hits, misses, writes and forgets.

ProfilingCollection

It allows you to measure time taken to perform actions in your code. There are 2 ways to do it.

Automatically:

Debugger::profileMe('event-name', function () {
    sleep(1);
});

Or manually:

Debugger::startProfiling('event-name');
usleep(300);
Debugger::stopProfiling('event-name');

Also helpers are available:

lad_pr_start();
lad_pr_stop();
lad_pr_me();

Extending

You can easily add your own data collections to debug output. Just look at how it was done in the package itself and repeat for anything you want (for example HTTP requests).

Contributing

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].