react js http post 500 internal server error 1

react js http post 500 internal server error

export default function callApi2(endpoint, method = 'GET', body) {

  let headers = { 'content-type': 'application/json' }
  console.log(body);

  return axios({
    method: method,
    url: `${Config.API_URL2}/${endpoint}`,
    data: JSON.stringify(body),
    headers: { 'content-type': 'application/json' },
  }).catch(err => {
    console.log(err);
  });

Here is what the above code is Doing:
1. We’re importing the axios library and the config file.
2. We’re creating a function called callApi2 that takes in three parameters: endpoint, method, and body.
3. We’re creating a headers object that contains the content-type.
4. We’re using axios to make a request to the endpoint.
5. We’re returning the response from the API.
6. We’re catching any errors that occur.

Similar Posts