0

I am using someone else's API and they unfortunately set up a GET request to send data to query a string and get back a list of objects with some sentences that match the string.

Now I have to use it for the part I am working on in the project.

On Postman when I make a GET request with the following format as a JSON object:

enter image description here

I get back the following data in the BODY which shows that it works:

{
    "data": [
        {
            "Score": 0.0980088697361664,
            "Title": "Anushka Avni International (AAI) takes pleasure in presenting itself as one of the renowned Suppliers and Exporter. We have huge assortment of agro products available with us. We feel proud when buyers come to us recognizing the standard quality which we offer in the world wide market."
        },
        {
            "Score": 0.08126642849224107,
            "Title": "About Us Anushka Avni International (AAI) takes pleasure in presenting itself as one of the renowned Suppliers and Exporter. We have huge assortment of agro products available with us. We feel proud when buyers come to us recognizing the standard quality which we offer in the world wide market. We follow the best practices while supplying… Read More.."
        },
        {
            "Score": 0.0,
            "Title": "Minor Fire at Vent Line Outlet of Degassing Tank On 2nd January 2019 at 1120 HRS, a minor fire occurred at Ammonia Plant, whereby gas vented out to the atmosphere (at elevated position) through the vent line of degassing tank caught fire. ERT Tier 1 was activated. Fire was put off by isolating all sources to the unit, introduced nitrogen and applied snuffing steam."
        },
        {
            "Score": 0.0,
            "Title": "Minor Accident at Main Guard House, Asean Bintulu Fertilizer (ABF) Sdn Bhd, Sarawak. While queuing up behind a turnstile barrier on the way exiting the Main Guard House, a reversing van knocked a stationary motorcycle that waiting behind the van causing the motorcycle and motorcyclist fell down. There was no injury except a slight damaged to the motorcycle."
        },
        {
            "Score": 0.0,
            "Title": "Contractors Suffered Minor Injury at Asean Bintulu Fertilizer (ABF) Sdn Bhd, Bintulu Sarawak Two (2) contractors (Injured Person-IP) were doing tree cutting using sky lift. While lowering the sky lift jib to lower work area, the sky lift jib suddenly snapped and fell onto the ground causing minor injury to the contractors. One (1) IP bruised his arm while the other IP suffered superficial cut on his shin. Incident was classified as First Aid Case and to be investigated as per normal investigation process."
        }
    ]
}

I referenced this question and found a way to send the string as a query using a GET request.

  const getDescription = async (string) => {
    const response = await fetch("/rank/" + string, {
      method: "GET",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
    });
    console.log(response);
  };

  useEffect(() => {
    getDescription("hello");
  }, []);

But I am getting a 404 Error:

Response
​
body: ReadableStream { locked: false }
​
bodyUsed: false
​
headers: Headers {  }
​
ok: false
​
redirected: false
​
status: 404
​
statusText: "NOT FOUND"
​
type: "basic"
​
url: "http://localhost:3000/rank/hello"

How would I get this to work if it even is possible?

Edit: I resorted to making the other person create a POST request instead.

yudhiesh
  • 3,560
  • 3
  • 7
  • 24
  • Api is at /rank not on /rank/string , as per your postman request. – deepak Dec 19 '20 at 10:48
  • Additionally, is `http://localhost:3000/rank/hello` correctly proxying the request to `http://localhost:5000/rank/hello` ( https://create-react-app.dev/docs/proxying-api-requests-in-development/ ) – Federkun Dec 19 '20 at 10:49
  • Yes that is right, in the question I followed linked above that was how they queried the string. – yudhiesh Dec 19 '20 at 10:50
  • In my `package.json` the proxy is set to `"proxy": "http://localhost:5000"`. – yudhiesh Dec 19 '20 at 10:51

0 Answers0