APITube Help Center

How to call the News API from Python, Java, Go and more

No SDK required — any language that can make an HTTPS request can query the News API with your key in a header or the api_key query parameter

Jacob Partington

Written by Jacob Partington

July 2, 2026

Open this example in the API Playground ↗

How to call the News API from Python, Java, Go and more

The APITube News API is plain HTTPS plus JSON, so any language that can send an HTTPS request can call it — no SDK required. Send a GET (or POST) to https://api.apitube.io/v1/news/everything, put your key in the X-API-Key header, and read the JSON back. The example below is the whole contract; every language snippet further down is the same request in different syntax.

curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.apitube.io/v1/news/everything?language.code=en&per_page=5"

What do you need to call the News API from any language?

Three things, and nothing else:

  • Base URL + endpoint: https://api.apitube.io/v1/news/everything — the main search endpoint that returns articles from all sources.
  • Your API key: sent either as an X-API-Key request header (recommended) or as an api_key query parameter in the URL. An Authorization: Bearer YOUR_API_KEY header also works. If no key is present, the API replies 401 with error code ER0201.
  • Query parameters: plain URL query values such as language.code=en, title=climate change and per_page=5. Dotted names like language.code are passed literally.

The response is JSON with a status field ("ok" on success), pagination fields (page, has_next_pages), a request_id for support, and a results array. Each item in results holds fields like id, title, href, published_at and language.

How do you call the News API from Python?

Use the standard requests library — send the key as a header and pass filters through params:

import requests

resp = requests.get(
    "https://api.apitube.io/v1/news/everything",
    headers={"X-API-Key": "YOUR_API_KEY"},
    params={"language.code": "en", "per_page": 5},
)
data = resp.json()
for article in data["results"]:
    print(article["title"], article["href"])

How do you call it from Java, Go, Ruby and C#?

The pattern is identical everywhere: build the URL, set the X-API-Key header, read results from the JSON.

Java (built-in java.net.http, Java 11+):

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.apitube.io/v1/news/everything?language.code=en&per_page=5"))
    .header("X-API-Key", "YOUR_API_KEY")
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Go (standard net/http):

req, _ := http.NewRequest("GET", "https://api.apitube.io/v1/news/everything?language.code=en&per_page=5", nil)
req.Header.Set("X-API-Key", "YOUR_API_KEY")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))

Ruby (standard net/http):

require "net/http"
require "json"

uri = URI("https://api.apitube.io/v1/news/everything?language.code=en&per_page=5")
req = Net::HTTP::Get.new(uri)
req["X-API-Key"] = "YOUR_API_KEY"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(req) }
JSON.parse(res.body)["results"].each { |a| puts a["title"] }

C# / .NET (HttpClient):

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Key", "YOUR_API_KEY");
var url = "https://api.apitube.io/v1/news/everything?language.code=en&per_page=5";
var json = await client.GetStringAsync(url);
Console.WriteLine(json);

How do you call it from PHP without the SDK?

If you would rather not add the SDK, curl from PHP core does the job:

$ch = curl_init("https://api.apitube.io/v1/news/everything?language.code=en&per_page=5");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: YOUR_API_KEY"]);
$response = json_decode(curl_exec($ch), true);
foreach ($response["results"] as $article) {
    echo $article["title"] . "\n";
}

Do you need an official SDK?

No — every example above uses only your language’s standard HTTP tools. Official SDKs exist for three languages and save you the URL-building and JSON parsing: Node.js (npm install @apitube/news-api), PHP (composer require apitube/news-api) and Python (pip install apitube). For those three, prefer the SDK; see how to install and use the Node.js SDK. For Java, Go, Ruby, C# and any other language, the plain HTTP request is the supported path — there is nothing extra to install. For the full parameter list, see the official News API parameter reference.

Common Questions

Where do I put the API key — header or URL?

Either works. The X-API-Key request header is recommended because it keeps the key out of logs and URLs. As an alternative you can append api_key=YOUR_API_KEY to the query string, which is handy for quick tests but riskier since URLs get logged. An Authorization: Bearer YOUR_API_KEY header is also accepted. See how to authenticate your API requests for the details.

Which endpoints can I call this way?

All of them. The same header-plus-URL pattern works for every /v1/... endpoint — /v1/news/everything, /v1/news/top-headlines, /v1/news/article, /v1/news/count and the rest. Only the path and the query parameters change; the authentication stays the same.

How many results can I get per request?

Set per_page to control page size. The default is 100 and the maximum is 250; ask for more and the API returns 400 with error code ER0171 (“Limit is out of range”). Use page together with per_page to walk through more results, and check has_next_pages in the response to know when to stop.

What rate limit applies?

Live keys are limited to 50 requests per minute. Space your calls out and reuse one HTTP client instead of opening a new connection per request. If you exceed the limit you receive a 429 response — see how to handle rate-limit errors before adding retry logic.


Related Articles