From c953962e8e64206078978ffa494b9aad6b567444 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 21 Oct 2022 15:39:14 +0200 Subject: [PATCH] docs: version-agnostic README Also, simplified default example to use gateway API, and not RPC --- README.md | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b93f970..e8fbc8d 100644 --- a/README.md +++ b/README.md @@ -42,34 +42,18 @@ npm install --save ipfs-geoip ### CDN -Instead of a local installation (and browserification) you may request a [remote copy from jsDelivr](https://www.jsdelivr.com/package/npm/ipfs-geoip): +Instead of a local installation (and browserification) you may request a specific +version `N.N.N` as a [remote copy from jsDelivr](https://www.jsdelivr.com/package/npm/ipfs-geoip): -** - -``` - -When using prebuilt bundle from CDN, `ipfs-geoip` will be exposed under `window.IpfsGeoip` - -**>=v9** - -```html - - - ``` -The response in the console looks like: +The response in the console should look similar to: ```js { "country_name": "USA", @@ -87,25 +71,25 @@ The response in the console looks like: ### With public gateways (default) -If `ipfs` is a string or array of strings with public gateway URLs, it will be used for +If `gateways` is a string or array of strings with public gateway URLs, it will be used for fetching IPFS blocks as [`application/vnd.ipld.raw`](https://www.iana.org/assignments/media-types/application/vnd.ipld.raw) -and parsing them as DAG-CBOR locally: +and parsing them as DAG-CBOR locally via [@ipld/dag-cbor](https://www.npmjs.com/package/@ipld/dag-cbor): ```js const geoip = require('ipfs-geoip') const exampleIp = '66.6.44.4' -const ipfsGw = ['https://ipfs.io', 'https://dweb.link'] +const gateways = ['https://ipfs.io', 'https://dweb.link'] try { - const result = await geoip.lookup(ipfsGw, exampleIp) + const result = await geoip.lookup(gateways, exampleIp) console.log('Result: ', result) } catch (err) { console.log('Error: ' + err) } try { - const result = await geoip.lookupPretty(ipfsGw, '/ip4/' + exampleIp) + const result = await geoip.lookupPretty(gateways, '/ip4/' + exampleIp) console.log('Pretty result: %s', result.formatted) } catch (err) { console.log('Error: ' + err)