Requests and Responses

The Request class provides many methods for examining the HTTP request for your application and extends the Symfony\Component\HttpFoundation\Request class.

Please note that Request do NOT sanitise your data, it is up to you to do that.

Retrieving The Request URI

use Nova\Http\Request;
$request = new Request();

GET/POST array of query params

public function index(Request $request)
{ return $request->all();

read specific param

public function index(Request $request)
{ return $request->input('item');

Get user's IP address

public function index(Request $request)
{ return $request->ip();

Determine if the request contains a given input item key

public function index(Request $request)
{ return $request->exists('item');

Retrieving The Request Method

$method = $request->method();
if ($request->isMethod('post'))
{ //

Determine If The Request Path Matches A Pattern

if ($request->is('admin/*'))
{ //

Get The Request URL

$url = $request->url();

Get The Full Request URL

$url = $request->fullUrl();

Get the current path info for the request

$url = $request->path();

Retrieve A Request URI Segment

$segment = $request->segment(1);

Retrieving A Request Header

$value = $request->header('Content-Type');

Retrieving Values From SERVER

$value = $request->server('PATH_INFO');

Determine If The Request Is Over HTTPS

if ($request->secure())
{ //

Determine If The Request Is Using AJAX

if ($request->ajax())
{ //

Determine If The Request Has JSON Content Type

if ($request->isJson())
{ //

Determine If The Request Is Asking For JSON

if ($request->wantsJson())
{ //

Checking The Requested Response Format

The Request::format method will return the requested response format based on the HTTP Accept header:

if ($request->format() == 'json')
{ //

This improved Response API, able to simplify the Framework's Response management. It is now possible to do in a Controller Method:

after doing a use:

use Nova\Support\Facades\Response;


// Create a Response instance with string content
return Response::make(json_encode($user));
// Create a Response instance with a given status
return Response::make('Not Found', 404);
// Create a Response with some custom headers
return Response::make(json_encode($user), 200, array('header' => 'value'));
// Create a response instance with JSON
return Response::json($data, 200, array('header' => 'value'));