|
1 |
| -# js-api-client |
2 |
| -A frontend Javascript client for BigDataCloud API services. |
| 1 | +# BigDataCloud Javascript API Client |
| 2 | + |
| 3 | + |
| 4 | +A frontend Javascript client for connecting to the API services provided by [BigDataCloud](https://www.bigdatacloud.net) |
| 5 | +This client works in plain Vanilla Javascript and also adds easy access if jQuery is available. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## What API services does [BigDataCloud](https://www.bigdatacloud.net) offer? |
| 10 | + |
| 11 | +BigDataCloud offers a range of extremely useful and fast APIs that can be utilised in both backend and frontend scenarios. |
| 12 | +From validating customer input live to the next generation of IP Geolocation technology, BigDataCloud has an API suitable to your needs. |
| 13 | + |
| 14 | +For a full list of APIs, visit our [documentation area](https://www.bigdatacloud.net/ip-geolocation-apis). |
| 15 | + |
| 16 | +You can access any and all BigDataCloud APIs with a free API Key. |
| 17 | +To get your API Key, just access your account and retrieve it from your [Account Dashboard](https://www.bigdatacloud.net/customer/account). |
| 18 | +If you are not yet a customer, it is completely free to join. |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +## Documentation |
| 23 | + |
| 24 | +For documentation specific to this api client, please read below. |
| 25 | +For more specific documentation to the APIs available, including endpoints, request and response data, please visit our [documentation area](https://www.bigdatacloud.net/ip-geolocation-apis). |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## Authentication / Identification |
| 30 | + |
| 31 | +To use this API client you must have a BigDataCloud API Key. |
| 32 | +To get your personal key, just access your account and retrieve it from your [Account Dashboard](https://www.bigdatacloud.net/customer/account). |
| 33 | +If you are not yet a customer, it is completely free to join. |
| 34 | + |
| 35 | +Simply provide this key when initiating the api client, and it will be included in all requests to the BigDataCloud API Server. |
| 36 | +If using the jQuery quick caller, you can provide the key in each request by appending the key parameter to the request payload. |
| 37 | +See the example below. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +## Manual Installation |
| 42 | + |
| 43 | +1. Download the included javascript file and place it in a publically accessible location |
| 44 | +2. Include the script tag `<script src="bigdatacloud_api_client.js" type="text/javascript"></script>` before your code execution |
| 45 | +3. If using jQuery, include the script after the jQuery declaration |
| 46 | +4. Initiate the API Client and make the required calls |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +## CDN Installation |
| 51 | + |
| 52 | +1. Include the CDN script tag `<script src="https://cdn.jsdelivr.net/gh/bigdatacloudapi/js-api-client@latest/bigdatacloud_api_client.min.js" type="text/javascript"></script>` before your code execution |
| 53 | +2. If using jQuery, include the script after the jQuery declaration |
| 54 | +3. Initiate the API Client and make the required calls |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +## Example usage |
| 59 | + |
| 60 | +```javascript |
| 61 | +<script src="https://cdn.jsdelivr.net/gh/bigdatacloudapi/js-api-client@latest/bigdatacloud_api_client.min.js" type="text/javascript"></script> |
| 62 | +<script type="text/javascript"> |
| 63 | + |
| 64 | + var apiKey='XXX'; // Your api key found at: https://www.bigdatacloud.net/customer/account |
| 65 | + |
| 66 | + //vanilla implementation |
| 67 | + var client=new BDCApiClient(apiKey); |
| 68 | + client.call( |
| 69 | + 'ip-geolocation-full', |
| 70 | + {'ip':'8.8.8.8'}, |
| 71 | + function(jsonResult) { |
| 72 | + console.log('Vanilla result',jsonResult); |
| 73 | + }, |
| 74 | + function(err,code) { |
| 75 | + console.log('Vanilla error',err,code); |
| 76 | + } |
| 77 | + ); |
| 78 | + |
| 79 | + |
| 80 | + //jQuery implementation |
| 81 | + if (typeof jQuery != 'undefined') { |
| 82 | + (function($) { |
| 83 | + $.BDCApi('ip-geolocation-full',{ |
| 84 | + data:{ |
| 85 | + ip:'8.8.8.8', |
| 86 | + key:apiKey |
| 87 | + }, |
| 88 | + success:function(jsonResult) { |
| 89 | + console.log('jQuery result',jsonResult); |
| 90 | + }, |
| 91 | + error:function(error,code) { |
| 92 | + console.error('jQuery eror',error,code); |
| 93 | + } |
| 94 | + }); |
| 95 | + })(jQuery); |
| 96 | + } |
| 97 | + |
| 98 | +</script> |
| 99 | +``` |
| 100 | + |
| 101 | + |
| 102 | +## Example output |
| 103 | + |
| 104 | +```javascript |
| 105 | +{ |
| 106 | + "ip": "8.8.8.8", |
| 107 | + "country": { |
| 108 | + "isoAlpha2": "US", |
| 109 | + "isoAlpha3": "USA", |
| 110 | + "m49Code": 840, |
| 111 | + "isoName": "United States of America (the)", |
| 112 | + "isoAdminLanguages": [ |
| 113 | + { |
| 114 | + "isoAlpha3": "eng", |
| 115 | + "isoAlpha2": "en", |
| 116 | + "isoName": "English" |
| 117 | + } |
| 118 | + ], |
| 119 | + "unRegion": "Americas/Northern America", |
| 120 | + "currency": { |
| 121 | + "numericCode": 840, |
| 122 | + "code": "USD", |
| 123 | + "name": "US Dollar", |
| 124 | + "minorUnits": 2 |
| 125 | + }, |
| 126 | + "wbRegion": { |
| 127 | + "id": "NAC", |
| 128 | + "iso2Code": "XU", |
| 129 | + "value": "North America" |
| 130 | + }, |
| 131 | + "wbIncomeLevel": { |
| 132 | + "id": "HIC", |
| 133 | + "iso2Code": "XD", |
| 134 | + "value": "High income" |
| 135 | + }, |
| 136 | + "callingCode": "1", |
| 137 | + "countryFlagEmoji": "🇺🇸" |
| 138 | + }, |
| 139 | + "location": { |
| 140 | + "isoPrincipalSubdivision": "California", |
| 141 | + "isoPrincipalSubdivisionCode": "US-CA", |
| 142 | + "city": "Mountain View", |
| 143 | + "postcode": "94043", |
| 144 | + "latitude": 37.42, |
| 145 | + "longitude": -122.09, |
| 146 | + "timeZone": { |
| 147 | + "ianaTimeId": "America/Los_Angeles", |
| 148 | + "displayName": "(UTC-08:00) Pacific Time (US & Canada)", |
| 149 | + "effectiveTimeZoneFull": "Pacific Daylight Time", |
| 150 | + "effectiveTimeZoneShort": "PDT", |
| 151 | + "UtcOffsetSeconds": -25200, |
| 152 | + "UtcOffset": "-07", |
| 153 | + "isDaylightSavingTime": true, |
| 154 | + "localTime": "2019-04-06T04:06:39.1691744" |
| 155 | + } |
| 156 | + }, |
| 157 | + "lastUpdated": "2019-04-06T09:09:36.1877959Z", |
| 158 | + "network": { |
| 159 | + "registry": "ARIN", |
| 160 | + "registryStatus": "assigned", |
| 161 | + "registeredCountry": "US", |
| 162 | + "registeredCountryName": "United States of America (the)", |
| 163 | + "organisation": "Google LLC", |
| 164 | + "isReachableGlobally": true, |
| 165 | + "isBogon": false, |
| 166 | + "bgpPrefix": "8.8.8.0/24", |
| 167 | + "bgpPrefixNetworkAddress": "8.8.8.0", |
| 168 | + "bgpPrefixLastAddress": "8.8.8.255", |
| 169 | + "totalAddresses": 256, |
| 170 | + "carriers": [ |
| 171 | + { |
| 172 | + "asn": "AS15169", |
| 173 | + "asnNumeric": 15169, |
| 174 | + "organisation": "Google LLC", |
| 175 | + "name": "GOOGLE", |
| 176 | + "registry": "ARIN", |
| 177 | + "registeredCountry": "US", |
| 178 | + "registeredCountryName": "United States of America (the)", |
| 179 | + "registrationDate": "2000-03-30", |
| 180 | + "registrationLastChange": "2012-02-25", |
| 181 | + "totalIpv4Addresses": 8698103, |
| 182 | + "totalIpv4Prefixes": 435, |
| 183 | + "totalIpv4BogonPrefixes": 0, |
| 184 | + "rank": 53, |
| 185 | + "rankText": "#53 out of 62,872" |
| 186 | + } |
| 187 | + ], |
| 188 | + "viaCarriers": [ |
| 189 | + { |
| 190 | + "asn": "AS7018", |
| 191 | + "asnNumeric": 7018, |
| 192 | + "organisation": "ATT Services Inc.", |
| 193 | + "registeredCountry": "US", |
| 194 | + "registeredCountryName": "United States of America (the)", |
| 195 | + "rank": 2 |
| 196 | + }, |
| 197 | + /*........*/ |
| 198 | + { |
| 199 | + "asn": "AS31019", |
| 200 | + "asnNumeric": 31019, |
| 201 | + "organisation": "Paulus M. Hoogsteder trading as Meanie", |
| 202 | + "registeredCountry": "NL", |
| 203 | + "registeredCountryName": "Netherlands (the)", |
| 204 | + "rank": 51153 |
| 205 | + } |
| 206 | + ] |
| 207 | + }, |
| 208 | + "confidence": "low", |
| 209 | + "confidenceArea": [ |
| 210 | + { |
| 211 | + "latitude": 18.0256672, |
| 212 | + "longitude": -66.5275345 |
| 213 | + }, |
| 214 | + /*........*/ |
| 215 | + { |
| 216 | + "latitude": 18.0256672, |
| 217 | + "longitude": -66.5275345 |
| 218 | + } |
| 219 | + ], |
| 220 | + "securityThreat": "unknown", |
| 221 | + "hazardReport": { |
| 222 | + "isKnownAsTorServer": false, |
| 223 | + "isKnownAsProxy": false, |
| 224 | + "isKnownAsMailServer": false, |
| 225 | + "isKnownAsPublicRouter": false, |
| 226 | + "isBogon": false, |
| 227 | + "isUnreachable": false |
| 228 | + } |
| 229 | +} |
| 230 | +``` |
0 commit comments