Click here to Skip to main content
16,022,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I send a get request: "http://127.0.0.1:8000/api/test" in PostMan and I get "API is working" in JSON body. Then I try send a post request: "http://127.0.0.1:8000/api/people" but I get and HTML file in JSON body. Here is my route/api.php in my laravel project
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Route::apiResource('people', PersonController::class);

Route::middleware('api')->group(function () {
    Route::apiResource('people', PersonController::class);
});

Route::middleware('api')->group(function () {
    Route::get('/test', function () {
        return response()->json(['message' => 'API is working']);
    });
});

Route::get('/test', function () {
    return response()->json(['message' => 'API is working']);
});
. I try change the IP address with others but get nowhere. Please explain for me.

What I have tried:

I try replace the IP address with others like localhost, 10.0.0.2
Posted

I don't know why you're trying to change the IP address at all. If you don't make a change to the server to change the address and port it's listening on, it's kind of pointless to change the address in Postman.

Look at the HTML page you're getting back in Postman. Chances are it's an error page that may have more details on the problem.

I don't do Laravel, but looking at what you posted tells me that you have a people resource but there's no code to process any requests for it. There's no 'get' defined like there is for 'test'.
 
Share this answer
 
Your endpoint doesn't appear to be hosted at /api/people. Try changing your postman POST to use /people instead. The page you are seeing will probably state something like resource not found because it can't find the endpoint.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900