In react.js I'm using axios from communication with server. every API is working well except one.
my URL in code is https://localhost:44338/api/Register/Register
but in browser network it looks like this https://localhost:44338/api%E2%80%8B%E2%80%8B/Register%E2%80%8B/Register
. My question is why is the URL is changing? See code below:
import axios from "axios";
const url = "https://localhost:44338/api";
const makeRequest = async (method, path, data, headers) => {
let response;
const defaultErrorMessage = "Sorry! your request has been declined.";
let requestInfo = {
method,
url: `${url}${path}`,
headers: {
'Content-Type': 'application/json'
}
}
if (data) {
requestInfo.data = data;
}
if (headers) {
requestInfo.headers = headers
}
await axios(requestInfo).then(res => {
if(res.status === 200 || res.status === 201) {
response = res;
response.success = true;
}else {
response.success = false;
response.message = defaultErrorMessage;
}
}).catch(err => {
if(err.response) {
response = err.response;
response.message = err.response.data || defaultErrorMessage;
}else {
response = {
message: defaultErrorMessage
};
}
response.success = false;
});
return response;
}
export { makeRequest };
this is where I`m calling this function
const registerRequest = async (payload) => {
return await makeRequest("POST", "/Register/Register", payload);
}
here is response which I find interesting in this case
{
data: "",
success: false,
status: 404
config: {
baseURL: "https://localhost:44338/api",
url: "/Register/Register"
//ect
},
request: {
responseURL: "https://localhost:44338/api/%E2%80%8B%E2%80%8B/Register%E2%80%8B/Register"
//ect
}
}