Home > Software design >  react native API response check
react native API response check

Time:08-12

I am new to react native, I want to know how I can check the API POST and GET response as we checked the response of the API in networking in react js.

Right now I'm using expo to set up the project and the expo go app to work around

I am sending a POST req and it was showing an error

Possible Unhandled Promise Rejection (id: 0):

so I want to check the body what response I am sending to the API to fix the issue.

CodePudding user response:

To send requests in react-native you use the javascript fetch function.

For example:

try {
    const response = await fetch("www.yourapi.com", { method: "GET" });

    let data = undefined;

    if (response.status === 200) {
        data = await response.json();
    }

    return data;
} catch (err: any) {
    console.log(err)
}
  • Related