0

Postman output:

HTTP/1.0 200 OK
Cache-Control: no-cache, private
Content-Type:  application/json
Date:          Fri, 08 Feb 2019 12:13:36 GMT

{"status":1,"msg":"success","celeb":[{"id":1,"name":"Test Name"....

I'm getting my json in postman like this. when I try to use fetch(), I'm getting an error json parse error, unknown identifier HTTP

fetch('https://myurl/fetch')
.then((response) => response.json())
   .then((response) => {...}

2 Answers 2

1
let func = async () => {
 const url = 'https://myurl/fetch';
 const data = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          token: await AsyncStorage.getItem(ACCESS_TOKEN), /*or whatever you have on your api*/
        }),
      };

  const response = await fetch(url , data);
  const responseData = await response.json();

  console.log(responseData);
}
Sign up to request clarification or add additional context in comments.

Comments

0

I believe you are missing to set to configure you API call method, headers, mode etc... Check out Fetch Examples for a better explanation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.