I am calling http://localhost:4502/api/assets.json in React app and getting 204- No Content Response | Community
Skip to main content
May 4, 2022

I am calling http://localhost:4502/api/assets.json in React app and getting 204- No Content Response

  • May 4, 2022
  • 1 reply
  • 730 views

Hello, 

I am trying to use an asset in the react app located in the ui.frontend of my project and to conduct some test to see if the api would work I called:

 

const myHeaders = new Headers();
    myHeaders.append("Authorization"`Basic YWRtaW46YWRtaW4=`);
    myHeaders.append("Content-Type""application/json");

     fetch(
      {
        method: "GET",
        headers: myHeaders,
        redirect: "follow",
      }
    )
      .then((response=> console.log(response))
      .catch((error=> console.log(error));
 
and I receive a response {type: 'cors', url: 'http://localhost:4502/api/assets/myAssetsFolder.json', redirected: false, status: 204, ok: true, …
I am able to call this endpoint in the browser, in curl and in Postman but cannot get any response in the react application. I have exhausted a search through the documentation and cannot find any information. I have allowed the HTTP Methods in CORS configuration also. Can some one confirm that I can call this API in a react application in AEM and why do I always get a response 204- No Content?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

DEBAL_DAS
May 5, 2022

Could you please refer this : https://wanago.io/2018/11/05/cors-cross-origin-resource-sharing/ and section: Access-Control-Allow-Origin header.