Skip to content

Quickstart

Website screenshots in Go

Use net/http to create a screenshot with one HTTPS request and no browser infrastructure to manage.

Ironfang Render uses a standard HTTPS API, so Go can call it with net/http and does not require an SDK. A successful request returns the image bytes directly, ready to write to a file.

Get a key

Create an API key in the portal. The secret is displayed once and stored as a hash. Save it in an environment variable rather than adding it to the source file.

Take a screenshot

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	body, _ := json.Marshal(map[string]any{
		"url":   "https://example.com",
		"width": 1280,
	})

	req, _ := http.NewRequest("POST",
		"https://api.ironfang.uk/renderwolf/v1/screenshot",
		bytes.NewReader(body))
	req.Header.Set("Authorization", "Bearer "+key)
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		var e struct {
			Error struct{ Code, Message string } `json:"error"`
		}
		json.NewDecoder(resp.Body).Decode(&e)
		panic(fmt.Sprintf("%s: %s", e.Error.Code, e.Error.Message))
	}

	out, _ := os.Create("shot.png")
	defer out.Close()
	io.Copy(out, resp.Body)
}

Handling errors

Successful render responses are binary. Errors use JSON in the form {"error": {"code", "message"}}. A missing or unrecognised key returns 401 invalid_api_key. A key without the renderwolf:render scope returns 403 insufficient_scope.

// io.Copy streams the response to disk without buffering the
// complete image in memory.

PDFs and templates

The same call shape works for /v1/pdf, and for templated images at /v1/image/{id}. Only the path and the body change.

Next