Add experimental.globalFetch() Labs API #1038
Conversation
Something to remember is that It might be an idea to look at the request method being used, and reflect that in the permission prompt, but then it would also make sense to have separate set of permissions for fetching from and writing to a remote site. |
@paul90 Yes that's true - right now |
maybe basic question but.. the var body in the example above is now holding as string ALL the text that written on about.html or just what about.html returns? |
@arni077 it will contain all the text inside the about.html file, as served by https://beakerbrowser.com |
@pfrazee cool, but what if a dat website wants to send simple string to https://beakerbrowser.com ? how we can do that? |
@arni077 not yet supported |
arni077: You can include data in your query portion of the URL if you're the one creating the server. I'll note that It's really frowned-upon to use GET requests like that. e.g.
|
@RangerMauve what do you mean by "frowned-upon " ? i dont understand how to send with the snippet you shared. suppose if i have this: how to send with get method to example.com if i am a dat website? |
@pfrazee when it will be supported? it is very important for my project. |
@arni077 "frowned-upon" means that people have found that it's a bad idea to use this method. It goes against how HTTP is supposed to work. However, your example would look like What language are you using for your server-side? |
@RangerMauve i use node.js. |
@RangerMauve No worries @arni077 Basically I plan to add support for POST and etc, but just need to think it through. It's on the todo list. |
Traditional web applications are able to make cross-origin requests by proxying through their own servers. That's not a possibility for Dat's serverless apps, which is a problem for a lot of apps. For instance, what if you wanted to fetch "open graph" metadata for a site before posting it on a social profile app (ie fritter).
This PR solves this issue with a new Labs API called
experimental.globalFetch
. It is functionally similar tofetch()
except for a few key differences:HEAD
andGET
are supported.For each new origin contacted, a new permission prompt will be created:
The permission will persist for every origin.
To use this API, add the
globalFetch
token to theexperimental.apis
array in the dat.json manifest:You can then use the API exactly as Fetch is used: