Using a Proxy for API Access
Step-by-step tutorial on automating API requests via a proxy server using the Go language. Learn how to bypass rate limits and geographic restrictions.
Олександр Л.
11 June 2025
2556
2556
11 June 2025
An Application Programming Interface (commonly known as an API) is a widespread practice today for communicating with websites and applications. Through APIs, you can exchange functions and data in a structured manner, easily integrating workflows and data streams between various sites, applications, and systems. For example, between your website and a data server, you can exchange information such as exchange rates, weather forecasts, product price updates, and much more. An API proxy server is needed for a number of reasons:
- The API may be limited to a specific maximum number of requests from a single IP per unit of time, and once the threshold is exceeded, your IP may be blocked;
- You may be denied access to the API due to your geographic region;
- The number of connections to the server may be restricted, sometimes significantly.
You need a proxy API to ensure that data exchange is not interrupted. In practice, this is achieved by automating the process by embedding code that contains the necessary parameters. Code can be written in various programming languages: Python, Go, Node.js, JavaScript, PHP, and others. We will use Go as an example, which is excellent for web programming. Keep in mind that to create this code, you should have some programming background (knowledge of what code is and what variables to define in it). Alternatively, hire a specialist to perform specific tasks.
Automating Data Exchange Between API and Proxy
Suppose you need to automate a proxy-API workflow to get tomorrow's weather forecast from the public domain Weather.com (we provide this strictly to create a visual code example). A step-by-step guide on how to work with a proxy server using the Go language looks as follows:
- Obtain the proxy address in the format
IP:port:username:password. For example,123.45.67.89:8080:user123:pass123. - Register on the WeatherAPI.com service to get your unique API key and the full endpoint URL from which you will fetch weather data, for instance,
https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q=Kyiv&days=2, wheredays=2is the parameter for retrieving weather data (e.g., for tomorrow). - Create the request code, which in our case will look like this:
Go
package main import ( "fmt" "io/ioutil" "net/http" "net/url" ) func main() { // === Step 1: Configure Proxy === proxyStr := "http://user123:[email protected]:8080" proxyURL, err := url.Parse(proxyStr) if err != nil { fmt.Println("Error in proxy address:", err) return } // === Step 2: Set up HTTP Client with Proxy === transport := &http.Transport{Proxy: http.ProxyURL(proxyURL)} client := &http.Client{Transport: transport} // === Step 3: Create Request to Weather API === apiKey := "abc123456789xyz" // ← your API key city := "Kyiv" // ← your city, in this case, Kyiv. apiURL := fmt.Sprintf("https://api.weatherapi.com/v1/forecast.json?key=%s&q=%s&days=2", apiKey, city) req, err := http.NewRequest("GET", apiURL, nil) if err != nil { fmt.Println("Error creating request:", err) return } // === Step 4: Send Request via Proxy (JSON format) === resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() // === Step 5: Read and Print Obtained Response === body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response:", err) return } fmt.Println("Response from API:") fmt.Println(string(body)) }
As a result of using a proxy API service, you will be able to retrieve the data you need after running this code. Note that writing and processing code in any programming language requires a development environment. In our example, it is the Go programming language, which you need to obtain by installing the appropriate software for your OS. The text editor needed for writing code and parsing JSON response files is Visual Studio Code, GoLand, or Sublime Text/Notepad++ (editors with syntax highlighting). You will also need a configured proxy server and a Command Prompt (Windows) or Terminal (MacOS/Linux) to execute the written code.
