crawlfetch

Go (Gin): download YouTube, TikTok and Instagram videos

A Gin handler around CrawlFetch is a dozen lines: bind the query, call the API, relay the JSON.

How it fits together

The handler validates url, calls /v1/resolve with a shared http.Client, and streams the API response back to the caller.

Go (Gin) example

r := gin.Default()
r.GET("/resolve", func(c *gin.Context) {
u := c.Query("url")
if u == "" {
c.JSON(400, gin.H{"message": "url is required"})
return
}
req, _ := http.NewRequestWithContext(c, "GET",
"https://api.crawlfetch.com/v1/resolve?url="+url.QueryEscape(u), nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("CRAWLFETCH_KEY"))
resp, err := client.Do(req)
if err != nil {
c.JSON(502, gin.H{"message": "upstream unavailable"})
return
}
defer resp.Body.Close()
c.DataFromReader(resp.StatusCode, resp.ContentLength, "application/json", resp.Body, nil)
})

Notes for Go (Gin)

  • Passing c as the context cancels the upstream call if the client disconnects.

FAQ

What about Echo or chi?

Identical upstream call; only the handler signature differs.

Related

Last updated 2026-10-25

Add video downloads to your product today.

1,000 credits on signup plus 500 every month. That is roughly 180 YouTube clips to start, with no card.

Create free account