Home > Mobile >  API works in postman but not with axios in React
API works in postman but not with axios in React

Time:11-27

here is my following API: enter image description here It works fine in postman but when I try using axios : enter image description here

export const getAccountBalance = (id) => async (dispatch, getState) => {
    try {
        dispatch({
        type: BALANCE_FETCH_REQUEST,
        });
    
        const {
        userLogin: { userInfo },
        } = getState();
    
        const config = {
        headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${userInfo.token}`,
        },
        };
        const { data } = await axios.get(`getAccountByAccountNo?accountNo=${id}`,config);
        console.log(data);
        dispatch({
            type: BALANCE_FETCH_SUCCESS,
            payload: data,
        });
    } catch (error) {
        dispatch({
            type: BALANCE_FETCH_FAIL,
            payload:
            error.response && error.response.data.message
                ? error.response.data.message
                : error.message,
        });
    }
};

Its exactly the same URL but its coming 404 not found enter image description here

Please help me I have to submit this college project!!

CodePudding user response:

Need to access absolute url path

const { data } = await axios.get(`http://localhost:6969/v1/api/getAccountByAccountNo?accountNo
  • Related