4

I hope I could find some help to the issue.

I'm using React Native and try to get some data from an API called Feiertage-API (https://feiertage-api.de/), that basically returns (should return) the official holidays in Germany.

Trying to use fetch in react native, returns:

Response {
   "_bodyBlob": Blob {
     "_data": Object {
       "blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
       "name": "api",
       "offset": 0,
       "size": 487,
       "type": "application/json",
     },
   },
   "_bodyInit": Blob {
     "_data": Object {
       "blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
       "name": "api",
       "offset": 0,
       "size": 487,
       "type": "application/json",
     },
   },
   "headers": Headers {
     "map": Object {
       "access-control-allow-origin": Array [
         "*",
       ],
       "content-type": Array [
         "application/json",
       ],
       "date": Array [
         "Tue, 31 Jul 2018 07:17:51 GMT",
       ],
       "server": Array [
         "nginx",
       ],
       "x-powered-by": Array [
         "PHP/7.0.31, PleskLin, PleskLin",
       ],
     },
   },
   "ok": true,
   "status": 200,
   "statusText": undefined,
   "type": "default",
   "url": "https://feiertage-api.de/api/?jahr=2019&nur_land=hb",
}

My fetch call looks as follows:

fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
                .then(response => console.log(response) )
                .catch(error => console.log(error));

GET-Parameters are: - jahr=2019 (for year, I think that's obvious) - nur_land=hb (specifying what state by short form)

The possibility is given to get JSONP by adding the get-parameter 'callback=mycallbackname'

If trying to show the data with: console.log(response.json())

the result is:

 Promise {
      "_40": 0,
      "_55": null,
      "_65": 0,
      "_72": null,
   }

What I'm expecting to see is exactly the data which is shown here -> https://feiertage-api.de/api/?jahr=2019&nur_land=hb

Would like to know how to extract the data out of the Response{....}.

1 Answer 1

9

You need to call .json() method on that response.

fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
            .then(response => response.json() )
            .then(data => console.log(data) )
            .catch(error => console.log(error));
Sign up to request clarification or add additional context in comments.

4 Comments

What the helll... I'd saw this on another thread here ain't had success though. Now copy&pasted your solution and everything works. Thank you so much, marked this as accepted answer.
It is important to note that response.json() returns a promise so you either have to await it or wrap it in a .then()
So it's asynchronus and the second .then command is called once the first one is done getting all the data? Is that correct?
Correct. The .catch() will only be called if any promise fails.

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.