0

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


1 Answer 1

3

You should use baseURL instead of baseUrl

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.