js-mentorship-razvan / javascript

Javascript study notes
GNU General Public License v3.0
22 stars 2 forks source link

Write a function that accepts a string ip address and returns country, city and ISP(use ipify API) #400

Closed odv closed 4 years ago

odv commented 4 years ago

Use ipfy API: https://geo.ipify.org/signup Documentation: https://geo.ipify.org/docs

Fetch: https://geo.ipify.org/api/v1?apiKey=YOUR_API_KEY&ipAddress=8.8.8.8

YOUR_API_KEY is your actual API key that you received when signing up

ipAddress will be the actual ip address you receive as input.

DO NOT PASTE API KEY IN COMMENTS. ALWAYS KEEP IT PRIVATE!

Example output: "Country: US, city: Mountain View, ISP: Google LLC"

RazvanBugoi commented 4 years ago
function queryIP(a) {
    fetch(`https://geo.ipify.org/api/v1?apiKey=at_FCRibpiLKO03V0l6G9Daiyd4q31He&ipAddress=${a}`)
    .then((response) => {
    return response.json();
})
    .then((myJson) => {
    console.log(`Country: ${myJson.location.country},`);
    console.log(`city: ${myJson.location.city},`);
    console.log(`ISP: ${myJson.isp}`);
    });}