Using APIs in website,the easy way
Ever felt that you want to use API search results in your website or web app, yet thought that its to cumbersome to use it.
Using Jquery, you can do it in a snap.Irrespective of the framework you use, React, Angular or pure Vanilla.
Make the basic structure :
You just need this much.
Here I have included the CDN link for jquery,you can also download and include it.
Getting the API key:
You can use any JSON based API, as per your requirement.Any JSON based response giving API will work fine with this.
Here I am airvisual API, as an example.
Visit:https://www.airvisual.com/air-pollution-data-api, to read documentation and get an API key to use in your website.
After getting the API key, we’ll get back to our code.
Getting API results in website:
As it gives JSON based response, we can simply make a getJSON call,to get results.
To make a JSON call, use the simple syntax, with your API link and key.
Here JSON.stringify is used to display the raw JSON in a parsed format.
Here is the sample response:
Suppose, if you want to see only the pollution part of the response, just use,
See the response,
Now use the results in your website, as you need it.Integrate any API easily and create wonderful results.
Happy Coding!!!