Skip to content
Advertisement

Problem with axios post request from Nuxt.js to external API

I’m trying for many hours now, to get a simple post request to my external api working from Nuxt.

It works as expected from a seperate node instance, I can POST and GET as needed with the following:

JavaScript

Also with curl:

JavaScript

So far so good, now I want to implement this in my Nuxt project. I had to set up a http proxy first, which I did in nuxt.config.js like this:

JavaScript

I’m pretty confident that the proxy is working, because I can get the data with the following method:

JavaScript

But whatever I do, the POST request does not work. This is how I tried:

JavaScript

I tried various different formats, e.g. like this:

JavaScript

But it does not seem to work. The request is running and aborts after a while with the following error in the terminal:

JavaScript

A few other things I already tried:

  • Running API and Nuxt locally

  • Using axios imported in template and as nuxt module

  • Request from builded and productive version

  • Async and synchronous methods

Steps to reproduce:

JavaScript

To test, if the API is working, you can POST with curl:

JavaScript

Thank you for reading. Any hint would be much appreciated!

Advertisement

Answer

I have found the problem. There was a server middleware configured, that was not needed anymore. It triggered at every POST request.

Stupid mistake, but this is how you learn, right? xD

The steps to reproduce are a working demo now, in case anyone needs something similar.

Cheers!

Here is the working demo again:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement