Использование прокси для работы с API
Олександр Л.
11 June 2025
2180
2180
11 June 2025
Application Programming Interface (also widely known as API) — is a common practice today for communicating with websites and applications. When using an API, it’s easy and structured to exchange functions and data, seamlessly integrating workflows and data streams between different websites, applications, and systems. For example, your website and data server can exchange information such as currency rates, weather forecasts, price updates on goods, and much more. API proxy server is needed for working with APIs for several reasons:
- An API may be limited to a certain maximum number of requests from a single IP per unit of time, and exceeding this limit may result in your IP being blocked;
- Access to the API might be denied based on your geographic region;
- The request rate to the server may be heavily restricted. You need a proxy API to ensure that data exchange isn’t interrupted. In practice, automation is used for this by inserting code containing the necessary data. The code can be written in various programming languages: Python, Go, Node.js, JavaScript, PHP, and others. We will use Go as an example, as it is well-suited for web programming. Keep in mind that creating code requires some programming background (knowledge of what code is and how variables are specified within it). Alternatively, hire a specialist to perform specific tasks.
Automate data exchange between API and proxy
Suppose you need to automate a proxy-API connection to get tomorrow’s weather forecast from the public domain Weather.com (we provide this example purely to create clear code later). A step-by-step guide on how to work with a proxy server using Go language would look like this:
- Obtain the proxy address in the format IP:port:username:password. For example, 123.45.67.89:8080:user123:pass123.
- Register on WeatherAPI.com to get your unique API key and the full URL from which you will receive weather data, for example, https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q=Kyiv&days=2, where days=2 means data for the following day.
- Create a request code, which in our case will look as follows:
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 weather API request ===
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 output the response ===
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println("API response:")
fmt.Println(string(body))
}
As a result of using a proxy API service, after running this code, you will be able to obtain the needed data.
Note that writing and managing code in any programming language requires a software environment for running code. In our example, it’s the Go programming language, which you must install via appropriate software for your OS. The text editor needed to write code and parse JSON response files can be Visual Studio Code, GoLand, Sublime Text, or Notepad++ (editors with syntax highlighting). You will also need a configured proxy server and a command line (Windows) or Terminal (MacOS/Linux) to run the code you wrote.
