Documentation
¶
Overview ¶
Package fetch is the fetch plugin of MyGo: pages make HTTP requests from Go with the fetch of its JavaScript package, @mygo-plugins/fetch, which takes and returns the standard Request options and Response. Requests made this way are not subject to CORS, may set any header (Origin, Cookie, User-Agent, ...) and read every response header but Set-Cookie, which a Response cannot hold.
mygo.Use(fetch.Plugin)
and in the frontend:
import { fetch } from "@mygo-plugins/fetch";
const res = await fetch("https://api.example.com/items", {
headers: { authorization: `Bearer ${token}` },
});
const items = await res.json();
The response body streams to the page as Go reads it, and aborting the request's signal cancels it in Go. URLs that are not http or https, such as the app's own pages, go to the webview's fetch.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Plugin = New(Options{})
Plugin is the plugin with the default options.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Client makes the requests; nil means http.DefaultClient. Its
// CheckRedirect limits the redirects followed when the request's
// redirect mode is "follow".
Client *http.Client
// Allow, when not nil, decides whether pages may make a request; a
// request it refuses rejects with an error.
Allow func(r *http.Request) bool
}
Options configure the plugin.