question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PUT and PATCH sending application/x-www-form-urlencoded data

See original GitHub issue

Using 0.5.4

I’m trying to use axios on my front end and fuel on the backend. Fuel Input::patch(‘param’) will give me data from the form request of type patch. This is also true for PUT. Perhaps also POST a.s.o.

When I use axios the data is empty and if I use jquery I get my data just fine.

        $.ajax({
            method: "PATCH",
            url: URL,
            data: {
                'firstname': this.state.account.firstname,
                'surname': this.state.account.surname,
            }
        })
        .done(function( msg ) {
            console.log(msg);
        });
        axios.patch(URL, {
                'firstname': this.state.account.firstname,
                'surname': this.state.account.surname,
            })
            .then((response) => {
                   console.log(response);
            });

The difference is if you look at chrome developer tools that jquery sends the data as formData and axios sends the data as json request payload.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:13
  • Comments:36 (3 by maintainers)

github_iconTop GitHub Comments

49reactions
molilycommented, Oct 19, 2015

How about axios including the above-mentioned serialization code so a Content-Type of application/x-www-form-urlencoded triggers the right encoding when an object is passed?

axios.post(
  '/foo',
  { some: 'data' },
  { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
);

… should work out of the box IMHO. Or do I miss something?

43reactions
nickuraltsevcommented, Jun 3, 2016

axios v0.12.0 supports URLSearchParams which can be used to send the data as application/x-www-form-urlencoded from the browser:

var params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
axios.post('/foo', params); 

Please note that URLSearchParams is not supported by all browsers, so you may need to polyfill it. (Make sure to add the polyfill to the global scope.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can HTTP PUT request have application/x-www-form ...
Yes you can use application/x-www-form-urlencoded with PUT. The HTTP spec does not limit what methods can be used with what media types.
Read more >
Retrofit — Send Data Form-Urlencoded - Future Studio
You may already know how to send data within the request body or how to make use of multipart/form-data to upload files using...
Read more >
POST, PUT & PATCH Requests with VueJS and Axios
A quick overview on how to submit form data securely to an API ... to the server is through JSON and application/x-www-form-urlencoded ....
Read more >
POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. ... application/x-www-form-urlencoded : the keys and values are encoded in key-value tuples ...
Read more >
Passing “x-www-form-urlencoded” body format data in REST ...
First let us try to see how we pass “x-www-form-urlencoded” ... Also choose the type of operation (GET/POST/PATCH/PUT) as per the guidelines ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found