Home > database >  axios using wrong base url
axios using wrong base url

Time:10-13

I have a react project where I'm making requests to a third-party api. I created an axios file where I set a baseUrl for requests, and I export a function which will make a request to a particular endpoint.

However, when I import and execute the function in my App.js, the request is made with localhost:3000 as the base url. Can't figure out why

I made a sandbox to demonstrate

here is the code for my axios.js file

import axios from 'axios'


const instance = axios.create({
    baseUrl: `https://api.-----.com/svc/topstories/v2/`
})

export const api_key = '------------------------'

export const getTopStories = async () => {
    const {data: {results}} = await instance.get(`/home.json?api-key=${api_key}`)
    return results
}
export default instance


CodePudding user response:

You should use baseURL instead of baseUrl

  • Related