1

I have localhost FastApi as a backend. It has only post method that write into db some data. I a new at vue. I have tested post method with python

data = {
    "page_id": "v1",
    "useragent": "Mozilla/5.0",
    "ip_adress": "1.1.1.1",
    "age": 31,
    "question": 1,
    "answer_array": str([1,2,3]),
    "other_answer": ""
}

requests.post('http://127.0.0.1:8000/events/v1/items', json=data)

FastApi said me that it is ok. INFO: 127.0.0.1:33472 - "POST /events/v1/items/ HTTP/1.1" 200 OK

The same thing I tried to do at web page. I have code

axios.post('http://127.0.0.1:8000/events/v1/items', JSON.stringify({
              "page_id": "v1",
              "useragent": "Mozilla/5.0",
              "ip_adress": "1.1.1.1",
              "age": 31,
              "question": 1,
              "answer_array": toString([1,2,3]),
              "other_answer": ""
            }) )
            .then(function (response) { console.log(response) } )
            .catch(function (error) { console.log(error) } )

But in that case my Fast Api said that is wrong INFO: 127.0.0.1:48180 - "POST /events/v1/items HTTP/1.1" 307 Temporary Redirect

I tried add JSON.stringify in idea that it doesn't serialized well Can you please help me/ What I doing wrong in vue code?

  • Does this answer your question? [How to send JSON data from Nuxt Axios to a FastAPI backend through a POST request?](https://stackoverflow.com/questions/73062925/how-to-send-json-data-from-nuxt-axios-to-a-fastapi-backend-through-a-post-reques) – Chris Nov 04 '22 at 14:20
  • See related answers [here](https://stackoverflow.com/a/71023536/17865804), as well as [here](https://stackoverflow.com/a/73761724/17865804) and [here](https://stackoverflow.com/a/71741617/17865804). – Chris Nov 04 '22 at 14:22
  • 1
    The issue is that your endpoint is registered with a ending slash (`/events/v1/items/`, while you're calling it without `/events/v1/items` - Starlette/FastAPI will issue a 307 redirect response in that case. – MatsLindh Nov 04 '22 at 14:59

0 Answers0