nnnayeem's avatar

Trying to build rest api using postman

Hello everyone. Currently I am working on a project where I am sending data using postman to my laravel app. I want to use laravel raw while the content type is html or plain text and I want to capture the data in laravel controller. So far, I succeeded using json. But I dont want to use json. Everytime I send data It gets me empty array. I also disabled the csrf token for that route. The code is added below:

        //I tried using this but shows empty array
        
        public function getData(Request $request){
                $p = $_POST;
                dd($p);
   
            }




        //I also tried this

            public function getData(Request $request){
                dd($request->all());
   
            }

Everytime gives me empty array. I tried using html raw like following:

        <input type="hidden" name="testing" value="v1>
0 likes
7 replies
nnnayeem's avatar

@Snapey could you give me a answer if you have the solutio of this problem?

Tray2's avatar

Are you using GET or POST?

If you are using GET you can try this

dd($request->query()):

If you are using POST you need to set the proper request headers. If I'm not misstaking there are two different kinds.

nnnayeem's avatar

I am using post. I am not setting header because after getting the result I can see that the postman automatically set the header.

In the raw I wrote like this for html:

<input type="hidden" name="testing" value="v1>

Is it okay or do I have to create a entire form in the raw? I tried creating a form but it does not work either.

Snapey's avatar

You don't post a form html with postman, you send the form data (if you want to pretend the data came from a client form)

In postman, in the Body section, enter key:value pairs

Snapey's avatar

Only you know what sort of API you are trying to build?

hollyit's avatar

When you post a form, the HTML code that generates that form doesn't get sent to the server. It gets encoded into a query string, so your hidden example would be testing=v1.

In postman, you can do that in the raw field (field1=somedata&field2=somedata). It's the same as a URL query string, but you must make sure you URL encode everything. The easier solution is to select form-data in Postman and just fill in the field names and values. Then it takes care of that part for you.

Please or to participate in this conversation.