Thanks for the response. I'm trying to replace an existing (old/crappy) API with a laravel API without requiring any changes to the front end client. The client currently sends all API requests as POSTs to a single endpoint with a json body containing a "method" (user/login from my example above) and other data.
My routes/api.php file is parsing the json of the request for routing something like "method": "user/login" to UserController@login
It is indeed handling the JSON posts just fine when I make requests via Postman, but when I try to run phpunit with tests making the requests it does not appear to get that json body/content.
Route::group(['prefix' => 'v0', 'middleware' => [V0Auth::class, HandleCors::class]], function () {
var_dump(request()->input('method'));
exit();
// parse the request json for the "method" and route to an appropriate Controller@action
When I make a request with Postman, I see the expected "user/login", but running the test with the same request (as far as I can tell) results in NULL.
Maybe I'm overthinking/complicating and doing something dumb, or just missing something. I'm just trying to understand why the request seems to be different. Here's the raw request in Postman that works:
POST /api/v0/ HTTP/1.1
Host: [redacted]
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache
Postman-Token: 4b6e7540-79ff-4249-b7f8-6e3847758a45
{
"method": "user/login",
"email": "[email protected]",
"password": "passwd"
}
I would think this code would result in the same request (and response):
$response = $this->json('POST', '/api/v0/', [
'method' => 'user/login',
'email' => '[email protected]',
'password' => 'passwd'
]);
Thanks again!
Brian