oleg
oleg

Reputation: 63

How can I use fetch with REST API?

How can I use fetch method for AJAX with REST API? Any example please.

I try to use

fetch('https://jsonplaceholder.typicode.com/posts').then( (r) => console.log( r ));

And did not get JSON as expected.

Upvotes: 4

Views: 1055

Answers (1)

Skif
Skif

Reputation: 1308

You should convert the promise result in JSON. Try to use

fetch('https://jsonplaceholder.typicode.com/posts')
   .then( (r)=> r.json() )
   .then( (r) => console.log( r ));

Upvotes: 1

Related Questions