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

222
Views
Axios Get Request Not Working on Host in Next.js

I have an API which gets records from Mongodb. When I call records from db, records are coming, there is no problem. But it's not working on the host. There is an error on console like Failed to load resource: the server responded with a status of 404 () api/improve-language?cat=general:1.

My codes where I'm trying to get datas:

useEffect(() => {
    getAllData(category)
  }, [])

  async function getAllData(cat){

    if(cat){
      cat = `?cat=${cat}`
    } else{
      cat = ``
    }
    
    axios
    .get(`/api/improve-language${cat}`)
    .then(res => {
      setAllWords(res.data)
      setNeverAskedWords(res.data)
      newQuestionAndAnswers(res.data)
    })
    .catch(err =>{
      console.log(err)
    })

  }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The 404 error means the address is wrong.

Probably your REST API and Next JS client are running on different addresses.
Can you call your GET endpoint with the exact address like http://localhost:3000/api/improve-language?

PS. for production-ready apps it will be better to pass the API address by env variable, so you will be able to change it dynamically.

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!