A basic Wails app that fetches quotes from the Tronald Dump API

Wails builds desktop apps with a Go backend and a web frontend rendered in the OS webview. This app has one button that fetches a random quote and shows it. There are two places you can make the HTTP call: in the frontend JavaScript, or in Go with the result passed to the frontend. I’ll show both.
Create the project
Section titled “Create the project”Install the Wails CLI and check your system has what it needs (Go, Node.js and, on Linux, the WebKitGTK libraries):
go install github.com/wailsapp/wails/v2/cmd/wails@latestwails doctorThen create a project from the Vue template:
wails init -n quoteapp -t vuecd quoteappOption 1: call the API from the frontend
Section titled “Option 1: call the API from the frontend”Replace frontend/src/components/HelloWorld.vue with:
<script setup>import { ref } from 'vue'
const quote = ref('')
async function getQuote() { const response = await fetch('https://api.tronalddump.io/random/quote') const data = await response.json() quote.value = data.value}</script>
<template> <div> <button @click="getQuote">Get quote</button> <p>{{ quote }}</p> </div></template>This request comes from the webview, so the API has to allow cross-origin requests. If it doesn’t, the browser blocks the response and you need option 2.
Option 2: call the API from Go
Section titled “Option 2: call the API from Go”Wails exposes the public methods of any struct you pass to Bind. The Vue template already binds an App struct in app.go; add a GetQuote method to it:
package main
import ( "context" "encoding/json" "fmt" "net/http")
type App struct { ctx context.Context}
func NewApp() *App { return &App{}}
func (a *App) startup(ctx context.Context) { a.ctx = ctx}
// GetQuote is callable from the frontend because it is exported.func (a *App) GetQuote() (string, error) { req, err := http.NewRequestWithContext(a.ctx, http.MethodGet, "https://api.tronalddump.io/random/quote", nil) if err != nil { return "", err } resp, err := http.DefaultClient.Do(req) if err != nil { return "", err } defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { return "", fmt.Errorf("quote API returned %s", resp.Status) }
var body struct { Value string `json:"value"` } if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { return "", err } return body.Value, nil}main.go from the template stays as it is. The part that matters is the Bind option:
err := wails.Run(&options.App{ Title: "quoteapp", Width: 1024, Height: 768, AssetServer: &assetserver.Options{ Assets: assets, }, OnStartup: app.startup, Bind: []interface{}{ app, },})When you run wails dev, Wails generates JavaScript wrappers for bound methods under frontend/wailsjs/go/main/App.js. Each wrapper returns a promise; if the Go method returns a non-nil error, the promise rejects. Use it from the component:
<script setup>import { ref } from 'vue'import { GetQuote } from '../../wailsjs/go/main/App'
const quote = ref('')const error = ref('')
async function getQuote() { try { quote.value = await GetQuote() error.value = '' } catch (err) { error.value = String(err) }}</script>
<template> <div> <button @click="getQuote">Get quote</button> <p>{{ quote }}</p> <p v-if="error">{{ error }}</p> </div></template>Going through Go avoids CORS entirely and keeps any API keys out of the frontend bundle.
Run and build
Section titled “Run and build”wails dev # live-reloading development buildwails build # production buildwails build writes the executable to build/bin. On Linux run ./build/bin/quoteapp; on macOS it’s an app bundle (quoteapp.app); on Windows, double-click quoteapp.exe.
© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)