How to use Postman for Laravel $_POST request

MisterCat picture MisterCat · Feb 1, 2016 · Viewed 46.4k times · Source

How can I try sending a post request to a Laravel app with Postman?

Normally Laravel has a csrf_token that we have to pass with a POST/PUT request. How can I get and send this value in Postman? Is it even possible without turning off the CSRF protection?

Answer

Björn picture Björn · Feb 1, 2016

Edit:

Ah wait, I misread the question. You want to do it without turning off the CSRF protection? Like Bharat Geleda said: You can make a route that returns only the token and manually copy it in a _token field in postman.

But I would recommend excluding your api calls from the CSRF protection like below, and addin some sort of API authentication later.

Which version of laravel are you running?

Laravel 5.2 and up:

Since 5.2 the CSRF token is only required on routes with web middleware. So put your api routes outside the group with web middleware.

See the "The Default Routes File" heading in the documentation for more info.

Laravel 5.1 and 5.2:

You can exclude routes which should not have CSRF protection in the VerifyCsrfToken middleware like this:

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'api/*',
    ];
}

See the "Excluding URIs From CSRF Protection" heading documentation for more info.