How to profile the laravel REST API

There's a big extension for laravel: debugbar. But what if I have a REST API. With the same lack of interface. How can I profile this type of application?

+4
source share
2 answers

Instead of returning an answer, send it to the view:

return \View::make('debug', ['data' => $response]);

instead

//return response()->json($response); 

(don't forget to create a view in which you echo data)

+1
source

You can try this middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\JsonResponse;

class ProfileJsonResponse
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        if (
            $response instanceof JsonResponse &&
            app()->bound('debugbar') &&
            app('debugbar')->isEnabled() &&
            is_object($response->getData())
        ) {
            $response->setData($response->getData(true) + [
                '_debugbar' => app('debugbar')->getData(),
            ]);
        }

        return $response;
    }
}

Link https://github.com/barryvdh/laravel-debugbar/issues/252

0
source

Source: https://habr.com/ru/post/1570166/


All Articles