intitial work on rest api

This commit is contained in:
Nabeel Shahzad
2017-08-14 18:26:20 -05:00
parent e19b84a078
commit bc94772ce2
10 changed files with 179 additions and 11 deletions

View File

@@ -0,0 +1,40 @@
<?php
/**
* https://stackoverflow.com/a/34894933
*/
namespace App\Http\Middleware;
use Closure;
class MeasureExecutionTime
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
// Get the response
$response = $next($request);
// Calculate execution time
$executionTime = microtime(true) - LUMEN_START;
// I assume you're using valid json in your responses
// Then I manipulate them below
$content = json_decode($response->getContent(), true) + [
'execution_time' => $executionTime,
];
// Change the content of your response
$response->setData($content);
// Return the response
return $response;
}
}