Back

Step by Step Guide to Building a Frame.io API Integration in Go

Aug 16, 20245 minute read

Introduction

Hey there, fellow developer! Ready to dive into the world of Frame.io API integration with Go? You're in for a treat. Frame.io's API is a powerhouse for video collaboration, and we're about to harness that power with the simplicity and efficiency of Go. Let's build something awesome together!

Prerequisites

Before we jump in, make sure you've got:

  • Go installed on your machine (you're a Go dev, so I'm sure you're covered!)
  • A Frame.io account with API credentials (if you don't have this, hop over to Frame.io and set it up real quick)

Setting up the project

Let's get our hands dirty:

mkdir frameio-integration cd frameio-integration go mod init frameio-integration

Now, let's grab the HTTP client we'll need:

go get github.com/go-resty/resty/v2

Authentication

First things first, let's get that access token. In your Frame.io dashboard, grab your API key. We'll use it to authenticate our requests.

Here's a quick snippet to get you started:

import "github.com/go-resty/resty/v2" client := resty.New() client.SetHeader("Authorization", "Bearer YOUR_API_KEY")

Making API requests

Now that we're authenticated, let's make some magic happen. Here's a basic structure for API calls:

resp, err := client.R(). SetResult(&result). Get("https://api.frame.io/v2/me") if err != nil { // Handle error }

Implementing key features

Listing projects

Let's fetch those projects:

type Project struct { ID string `json:"id"` Name string `json:"name"` } var projects []Project _, err := client.R(). SetResult(&projects). Get("https://api.frame.io/v2/projects")

Uploading assets

Time to upload some cool stuff:

resp, err := client.R(). SetFile("file", "path/to/your/file.mp4"). SetFormData(map[string]string{ "type": "file", "name": "awesome_video.mp4", }). Post("https://api.frame.io/v2/assets")

Managing comments

Let's add a witty comment:

comment := map[string]interface{}{ "text": "This scene is pure gold!", "timestamp": 1234, } resp, err := client.R(). SetBody(comment). Post("https://api.frame.io/v2/comments")

Sharing is caring:

var reviewLink struct { URL string `json:"url"` } _, err := client.R(). SetResult(&reviewLink). Get("https://api.frame.io/v2/review_links/ASSET_ID")

Error handling and best practices

Always check for errors, folks! And remember, Frame.io has rate limits. Be a good API citizen:

if resp.StatusCode() == 429 { // Back off and retry }

Testing the integration

Don't forget to test! Here's a simple example:

func TestListProjects(t *testing.T) { // Your test code here }

Optimizing performance

Want to speed things up? Try concurrent requests:

var wg sync.WaitGroup for _, projectID := range projectIDs { wg.Add(1) go func(id string) { defer wg.Done() // Make API call }(projectID) } wg.Wait()

Conclusion

And there you have it! You've just built a Frame.io API integration in Go. Pretty cool, right? Remember, this is just the beginning. There's so much more you can do with Frame.io's API. Keep exploring, keep coding, and most importantly, have fun!

For more details, check out the Frame.io API documentation. Now go forth and create something amazing!