Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

333
Views
PUT request with express and axios keeps giving me 404 (using a React-Redux form)

I have a form that I'm trying to use to update a React component. The state seems to be altered because it re-renders no problem when I hit submit, but the data doesn't persist. More importantly, I get a 404 saying that the json object I'm trying to change can't be found.

I think it's something to do with how I'm trying to use my axios request in my actions, but I wouldn't be surprised if I'm off base from looking at this for too long.

Here are the relevant tidbits

Routes

const User = db.model('user')
const router = require('express').Router();

router.put('/:id', (req, res, next) => {
  User.findById(req.params.id)
  .then(user => user.update(req.body))
  .then(updated => res.status(201).json(updated))
  .catch(next)
})

Actions

const editUser = (userId, userInfo) => ({
  type: UPDATE_USER,
  userId,
  userInfo
})

export const updateUser = function(id, info) {
  return dispatch => {
    dispatch(editUser(id, info))
    axios.put(`/api/users/${id}`, {info})
      .catch(err => console.error("Wasn't able to update user.", err))
  }
}

Here are the errors I'm getting

POST http://localhost:1337/api/users/1  Wasn't able to update property. 404 (Not Found) 
Error: Request failed with status code 404
        at createError (createError.js:15)
        at settle (settle.js:18)
        at XMLHttpRequest.handleLoad (xhr.js:77)

And that URI totally exists, so I don't really see why the request seems to think otherwise.

Any help is appreciated!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Figured it out. Needed an extra line using .then to actually send the information to the my db.

export const updateUser = function(id, info) {
      return dispatch => {
        dispatch(editUser(id, info))
        axios.put(`/api/forSale/${id}`, info)
          .then(res => res.data)
          .catch(err => console.error("Wasn't able to update property.", err))
      }
    }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!