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
cas 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