3.7.7 • Published 2 years ago

gun-fetch v3.7.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

gun-fetch

Fetch With GunDB

const path = require('path')
const options = {file: path.resolve('./storage'), relay: false}
// file: path where data will be saved
// relay: boolean, truthy means that gun-fetch will connect to relays, falsy means that gun-fetch will not connect to any relays

const gunFetch = require('gun-fetch')

const fetch = gunFetch(options)

let test = await fetch('gun://hello/test/testing', {method: 'GET'})

let testText = await test.text()

// show the data
console.log(testText)

this readme will be updated soon, there has been a lot of changes, the method HEAD is now supported

special characters

gun-fetch uses special characters to make specific types of queries | Character | Type | | ------------- |:-------------:| | _ | special queries | | - | hex encoded |

usage

METHODS

HEAD:

someHostName or someHostName/somePath, if data is found then code 200 is returned, no body is returned

_someHostName or _someHostName/somePath, if data is found then code 200 is returned, no body is returned

_, only headers are used with a request, no body is returned

HEADERS:

Authorization, hostname must be _someUser or _someUser/somePath, makes a query for a user that is logged in and returns with a code 200 if the data is found

X-Node, hostname must be _, should contain a string which will be the url for the gundb relay, returns X-Node header and code 200 if gun-fetch is connected to the relay

X-Nodes, hostname must be _, should contain a stringified javascript array which will contain the urls of gun relays, returns X-Nodes and code 200 if gun-fetch is connected to all of the relays

X-Peer, hostname must be _, should contain a string which will be the url for the gundb relay, returns X-Peer header and code 200 if gun-fetch connects to the relay

X-Peers, hostname must be _, should contain a stringified javascript array which will contain the urls of gun relays, returns X-Peers and code 200 if gun-fetch connects to all of the relays

more to come

fetch('gun://_', {method: 'HEAD', headers: {'X-Node': 'https://some-gun.relay/gun'}}) | if the method is HEAD and the hostname is only _, then | gun.get(~@someuser)\

fetch('gun://_someuser') | if the text after _ does not contain special characters, then this will be a user/relay query | gun.get(~@someuser)\

fetch('gun://_some.gun-key_here') | if the text after the _ contains special characters, then it will be a public key query | gun.get(~some.pub-key_here)\

fetch('gun://_', {method: 'PUT', body: JSON.stringify({user: 'someuser', pass: 'somepass'})}) | if there is only _ without any text, then this will be a user register/login query | gun.user()\

fetch('gun://somedata') | if there is no _ with text, then it will be a regular query | gun.get(somedata)

fetch('gun://somedata/someotherdata') | if there is no _ with text, then it will be a regular query | gun.get(somedata).get(someotherdata)

fetch('gun://-736f6d657465737474657874') | if there is a - then it will decode the hex encoded query | - means decode 74657374696e67 which decodes into "testing", which means it will be gun.get(testing)

fetch('gun://_', {method: 'GET', headers: {'X-Alias': 'someAliasHere'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://some/data/to/paginate', {method: 'GET', headers: {'X-Paginate': 'someGunDBPaginateObject'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://some/data/to/check', {method: 'GET', headers: {'X-Not': 'true'}}) | if the headers have a headers['X-Alias'] key then it will return whether that alias is logged in or not

fetch('gun://_', {method: 'PUT', headers: {'X-Create': 'someAliasHere'}, body: 'somePasswordHere'}) | if the headers have a headers['X-Create'] key then a new user will be created like gun.user().create()

fetch('gun://_', {method: 'PUT', headers: {'X-Login': 'someAliasHere'}, body: 'somePasswordHere'}) | if the headers have a headers['X-Auth'] key then the user will be logged in like gun.user().auth()

fetch('gun://somedata/some/path/to/data', {method: 'PUT', headers: {'X-Set'}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers have a headers['X-Set'] key then the data will be used in a gundb set query like gun.get('somedata').get('some').get('path').get('to').get('data').set({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'PUT', headers: {}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers does not have a headers['X-Set'] key then the data will be used in a gundb put query like gun.get('somedata').get('some').get('path').get('to').get('data').put({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'DELETE', headers: {'X-Unset': 'true'}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers have a headers['X-Set'] key then the data will be used in a gundb unset query like gun.get('somedata').get('some').get('path').get('to').get('data').unset({message: 'message', data: 'data'})

fetch('gun://somedata/some/path/to/data', {method: 'DELETE', headers: {}, body: JSON.stringify({message: 'message', data: 'data'})}) | if the headers does not have a headers['X-Unset'] key then the data will be null in a gundb put query like gun.get('somedata').get('some').get('path').get('to').get('data').put(null)

fetch('gun://_', {method: 'DELETE', headers: {'X-Logout': 'someAliasHere'}}) | if the headers have a headers['X-Logout'] key then the alias will be logged out like gun.user().leave()

fetch('gun://_', {method: 'DELETE', headers: {'X-Delete': 'somePasswordHere'}, body: 'somePasswordHere'}) | if the headers ave a headers['X-Delete'] key then the alias will be deleted like gun.user().delete()

notes

more to come

3.7.5

2 years ago

3.7.4

2 years ago

3.7.3

2 years ago

3.7.2

2 years ago

3.7.7

2 years ago

3.7.6

2 years ago

3.6.0

2 years ago

3.7.1

2 years ago

3.7.0

2 years ago

3.3.9

2 years ago

3.3.8

2 years ago

3.3.7

2 years ago

3.3.6

2 years ago

3.5.7

2 years ago

3.5.6

2 years ago

3.5.5

2 years ago

3.5.4

2 years ago

3.5.9

2 years ago

3.5.8

2 years ago

3.4.0

2 years ago

3.4.4

2 years ago

3.4.3

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.4.8

2 years ago

3.4.7

2 years ago

3.4.6

2 years ago

3.4.5

2 years ago

3.4.9

2 years ago

3.3.5

2 years ago

3.2.1

2 years ago

2.9.9

2 years ago

3.2.0

2 years ago

3.2.6

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.2.9

2 years ago

3.2.8

2 years ago

3.2.7

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.8

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.0

2 years ago

3.0.9

2 years ago

3.3.0

2 years ago

3.3.4

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

2.9.4

2 years ago

2.9.3

2 years ago

2.9.6

2 years ago

2.9.5

2 years ago

2.9.8

2 years ago

2.9.7

2 years ago

2.6.0

2 years ago

2.8.1

2 years ago

2.6.3

2 years ago

2.8.0

2 years ago

2.6.2

2 years ago

2.9.2

2 years ago

2.7.4

2 years ago

2.5.6

2 years ago

2.9.1

2 years ago

2.7.3

2 years ago

2.5.5

2 years ago

2.7.6

2 years ago

2.5.8

2 years ago

2.7.5

2 years ago

2.5.7

2 years ago

2.7.8

2 years ago

2.7.7

2 years ago

2.5.9

2 years ago

2.7.9

2 years ago

2.7.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.9.0

2 years ago

2.7.2

2 years ago

2.5.4

2 years ago

2.7.1

2 years ago

2.5.3

2 years ago

2.8.3

2 years ago

2.6.5

2 years ago

2.8.2

2 years ago

2.6.4

2 years ago

2.8.5

2 years ago

2.6.7

2 years ago

2.8.4

2 years ago

2.6.6

2 years ago

2.8.7

2 years ago

2.6.9

2 years ago

2.8.6

2 years ago

2.6.8

2 years ago

2.8.9

2 years ago

2.8.8

2 years ago

2.3.0

2 years ago

2.5.0

2 years ago

2.4.1

2 years ago

2.3.2

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.4.3

2 years ago

2.3.4

2 years ago

2.4.2

2 years ago

2.3.3

2 years ago

2.4.5

2 years ago

2.3.6

2 years ago

2.4.4

2 years ago

2.3.5

2 years ago

2.4.7

2 years ago

2.3.8

2 years ago

2.3.7

2 years ago

2.4.9

2 years ago

2.4.8

2 years ago

2.3.9

2 years ago

2.2.9

2 years ago

2.2.7

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago