Fetching Instagram profiles concurrently in Go with HikerAPI
HikerAPI has official clients for Python and Node, but not for Go. I wanted to pull public Instagram profile data (followers, post count, bio) from a Go program, so I wrote a small client using only the standard library. By the end of this post you'll have a CLI that: takes a list of usernames, fetches them concurrently with a bounded worker pool, prints one JSON object per line (ready for jq or…
HikerAPI offers official clients for Python and Node, but lacks a Go client. The author decided to create a Go client to retrieve public Instagram profile data (followers, post count, bio) using only the standard library. A CLI was developed that accepts a list of usernames, fetches them concurrently with a worker pool, and prints JSON objects per line ready for jq or .jsonl files.
A test is included, running against a fake server to avoid spending API credits. To get started, create an account at hikerapi.com and generate an access key. The endpoint used is GET https://api.hikerapi.com/v2/user/by/username?username= with the header x-access-key: your-access-key. The response wraps the profile in a user object, and only the needed fields are decoded, ignoring the rest.
A custom type FlexID handles the user ID (pk) that can appear as a number or string, ensuring proper decoding. A Client struct is defined with a key, base URL, and http.Client for making requests. The UserByUsername method fetches a profile by username, handling potential errors and encoding the response. Two decisions worth noting are setting base as a field for testing and including an empty-username check.
To fetch multiple profiles concurrently, a fixed pool of workers reads from a channel. The client is tested using net/http/httptest, covering real parsing and error handling without network requests.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.