0

I've created a Restful API using Laravel 5.4. I am using postman to test this API. I am sending postcode and building_number in the body of the request. when I click on the Send button, I am getting Status code 200 OK in the postman console but only getting postcode value in the response and not the building_number. Also, not getting the response message i.e.

  'msg' => 'found postcode',

Below is the screen shot from postman

Postman response

My route file is as

web.php

Route::group(['prefix' => 'api/v1'], function(){

    Route::post('paf', ['uses' => 'PafController@getAddress']);

});

and the controller is

PafController

public function getAddress(Request $request)
{
    $postcode = $request->input('postcode');
    $building_number = $request->input('building_number');

    $result = [
        'post_code' => $postcode,
        'building_number' => $building_number
    ];

    $response = [
        'msg' => 'found postcode',
        'address' => $result
    ];

    return response()->json($response, 200);
   }

please can someone advise why I am not getting back the full response?

1 Answer 1

1

Define your route inside routes/api.php instead since it's an api you're building. This will automatically make laravel-rest.dev/api/paf available to you. All routes inside routes/api.php are prefixed with /api

Route::post('paf', ['uses' => 'PafController@getAddress']);

In postman select form-data option, right below body, instead of raw

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.