Tuesday, January 11, 2022

fetch() web API to load data from server

 fetch

    ('https://crossorigin.me/https://www.metaweather.com/api/location/2487956/')

    .then(result => {

        console.log(result);

        return result.json(); //fetch () will return a promise and converting to json object

    })

     .then(data=>console.log(data))

    .catch(error => {

        console.log(error);

    });

here https://crossorigin.me is used to prevent same origin policy.

No comments:

Post a Comment

Testing controller

------Controller------------- @RestController @RequestMapping("/items") public class ItemController {     private final ItemServic...