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

90
Views
Routing Problem in calling API from REACT using Redux

I have create api with Python (django restframework). I am calling that api from my react applicaation using redux.

It works fine when i call it like this

   const {data} = await axios.get(`http://127.0.0.1:8000/api/products/${id}`)

but when i change the url to

    const {data} = await axios.get(`api/products/${id}`)

It then makes a request to a different route ( http://localhost:3000/product/api/products/6) and I want it to make a call to (http://localhost:8000/api/products/6

I have added the path in django server and allowed calls from the react app. and it is working perfectly when i was working with other routes.

for example it was working fine when i was making call to this route

const {data} = await axios.get('api/products/')
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to give the url to the api. If you don't provide full url, it will add your react app url.

You can declare a variable with the route

API_URL = "http://localhost:8000/"
const {data} = await axios.get(`${API_URL}api/products/${id}`)
about 4 years ago · Juan Pablo Isaza Report

0

module.exports = {
  //...
  devServer: {
    proxy: {
      '/api': {
         target: 'http://127.0.0.1:8000',
         changeOrigin: true,
      },
    },
  },
 };

Add the above configuration to your webpack,then the request can be forwarded by wepack dev server.

more details,please visit https://webpack.js.org/configuration/dev-server/#devserverproxy

about 4 years ago · Juan Pablo Isaza 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!