Fetch Interface based on URLs/ HTTP Methods #229
Replies: 2 comments 1 reply
-
Nice! ⭐ Sorry for the wall of text here, I'm just enthusiastic about this :) Big picture thoughtsI had assumed people would build Earthstar apps by using the Storage API and Layers APIs provided by this Javascript implementation, and we'd achieve app portability around those APIs by making a variety of swappable classes that work in different settings (browser, node, etc). Now there are other access patterns emerging, like this fetch API and a graphQL interface. This is a good thing:
Standard methods across access patternsTo avoid fragmentation let's try to use the same the method names across REST, fetch, graphQL, etc. I've just added a bunch of documentation about these methods to types.ts, especially
URL detailsThe workspace and author address formats are designed to work well in URLs with two caveats:
These rules make them URL-safe:
So except for the base58 case issue, these are all guaranteed to be valid URLs.
examples, using
The HTTP verbsLet's add Pubs & swarmsThe There will be 2 kinds of swarms:
Swarm passwords are just secret strings you share with friends. They let you connect only to trusted peers when you're in a very large or public workspace to protect your IP address privacy. (Swarms aren't implemented yet) |
Beta Was this translation helpful? Give feedback.
-
Parsing earthstar:// URLs -- case sensitivity problemsI tried shoehorning this into the javascript let orig = 'earthstar://+gardening.xXxXx/@suzy.xxx';
// parse it.
// URL() expects protocol to be http, so let's hack it
// also have to remove the '+'
let hacked = orig.replace('earthstar://+', 'http://');
let url = new URL(hacked)
console.log(url);
// extract info from the parsed URL
let workspace = '+' + url.host;
let author = null;
let path = null;
if (url.pathname.startsWith('/@')) {
author = url.pathname.slice(1); // remove leading slash
} else {
path = url.pathname;
}
console.log(workspace, author, path);
// --> +gardening.xxxxx @suzy.xxx null Switch to base32?Maybe we need to switch Earthstar keys from base58 to base32 so it can be case insensitive. It would make them 8 characters longer.
They would still fit in the limit of 63 characters for domain name segments (between periods). Added issue #29 for this idea |
Beta Was this translation helpful? Give feedback.
-
What's the problem you want solved?
I'd like to integrate protocol handlers for EarthStar in Electron apps or other browser-like apps, specifically in my p2p web browser project.
Ideally it should provide read and write access to stuff and have key management handled by the protocol handler.
We talked about this a bit on SSB here: %MbsFkcmbZU/pnx5JS5PpcVDtueMM0xslrzAXpqXfDwE=.sha256
Is there a solution you'd like to recommend?
I'd like to propose something that looks like the following psudo code:
I think that this could also be adapted for an HTTP API for some sort of daemon where
earthstar://
could be repalced withhttp://somgateway.com/someapi/path/
to point at an HTTP server running either locally or remotely.I'm interested in making a JS library called
earthstar-fetch
which will encapsulate this functionality in a similar way to dat-fetch and play around with it before drafting a full standard. A side effect would be that we'd get a fetch-like interface into regular web browsers along side protocol handlers in browsers like Agregore.Beta Was this translation helpful? Give feedback.
All reactions