Qaynaq LABS · TOOLS

CURL → CODE · GET · BASIC

cURL → 10 languages

GET api.stripe.com · secrets replaced with env vars.

Source cURL
curl -X GET https://api.stripe.com/v1/subscriptions/sub_123456789 -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:

Python · requests

import os
import requests

response = requests.get(
    "https://api.stripe.com/v1/subscriptions/sub_123456789",
    auth=(os.environ["STRIPE_SECRET_KEY"], "")
)
response.raise_for_status()

Python · httpx

import os
import httpx

response = httpx.get(
    "https://api.stripe.com/v1/subscriptions/sub_123456789",
    auth=(os.environ["STRIPE_SECRET_KEY"], "")
)
response.raise_for_status()

Node.js · fetch

import fetch from 'node-fetch';

const response = await fetch('https://api.stripe.com/v1/subscriptions/sub_123456789', {
  headers: {
    'Authorization': 'Basic ' + Buffer.from(process.env.STRIPE_SECRET_KEY + ':').toString('base64')
  }
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);

Node.js · axios

import axios from 'axios';

const response = await axios.get('https://api.stripe.com/v1/subscriptions/sub_123456789', {
  auth: {
    username: process.env.STRIPE_SECRET_KEY
  }
});

Go · net/http

package main

import (
	"net/http"
	"os"
)

func main() {
	req, err := http.NewRequest("GET", "https://api.stripe.com/v1/subscriptions/sub_123456789", nil)
	if err != nil {
		panic(err)
	}
	req.SetBasicAuth(os.Getenv("STRIPE_SECRET_KEY"), "")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		panic("request failed")
	}
}

PHP · cURL

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/subscriptions/sub_123456789');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, getenv('STRIPE_SECRET_KEY') . ':');
$response = curl_exec($ch);
if (curl_errno($ch)) {
    throw new Exception(curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
    throw new Exception("HTTP error: $httpCode");
}
curl_close($ch);
?>

Ruby · net/http

require 'net/http'
require 'uri'

uri = URI.parse('https://api.stripe.com/v1/subscriptions/sub_123456789')
req = Net::HTTP::Get.new(uri)
req.basic_auth(ENV['STRIPE_SECRET_KEY'], '')

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
unless res.is_a?(Net::HTTPSuccess)
  raise "HTTP error: #{res.code}"
end

Swift · URLSession

import Foundation

let url = URL(string: "https://api.stripe.com/v1/subscriptions/sub_123456789")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
let authString = "\(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? ""):"
request.setValue("Basic \(authString.data(using: .utf8)!.base64EncodedString())", forHTTPHeaderField: "Authorization")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        fatalError("Request failed: \(error)")
    }
    guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
        fatalError("HTTP request failed")
    }
    // Process data
}
task.resume()
RunLoop.main.run()

Rust · reqwest

use reqwest::blocking::Client;
use std::env;

fn main() {
    let client = Client::new();
    let response = client
        .get("https://api.stripe.com/v1/subscriptions/sub_123456789")
        .basic_auth(env::var("STRIPE_SECRET_KEY").unwrap(), Some(""))
        .send()
        .expect("Failed to send request");

    if !response.status().is_success() {
        panic!("Request failed with status: {}", response.status());
    }
}

C# · HttpClient

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        var client = new HttpClient();
        var authToken = Convert.ToBase64String(
            System.Text.Encoding.ASCII.GetBytes($"{Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY")}:")
        );
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authToken);

        var response = await client.GetAsync("https://api.stripe.com/v1/subscriptions/sub_123456789");
        response.EnsureSuccessStatusCode();
    }
}

Translation notes

  • Basic auth is used with the username set to the secret key and empty password
  • Environment variable STRIPE_SECRET_KEY holds the API key
  • All implementations use idiomatic HTTP clients for their language
  • Error handling checks HTTP status but does not parse error bodies

Common pitfalls when porting

  • Forgetting to set the empty password in basic auth
  • Not handling HTTP errors properly (e.g., ignoring status codes)
  • Using raw strings for secrets instead of environment variables
  • Not setting the correct Content-Type header (not needed for GET)
  • Assuming the API key can be used directly without base64 encoding for basic auth

About cURL → code translation

cURL is the lingua franca of API documentation: every vendor docs page ships a cURL snippet you can paste into a terminal and immediately see the API working. Translating that into your actual application code shouldn't be a 20-minute Stack-Overflow safari, but without a good translator it usually is.

Qaynaq Labs' cURL → code tool reads the full command — method, URL, headers, query params, body type, and auth — and emits idiomatic client code in 10 languages. Authentication goes through environment variables by default, request bodies become language-native data structures (not raw JSON strings), and minimal error handling is included.

Frequently asked

Why is the password empty in basic auth?

Stripe's API expects the API key as the username in Basic Auth, with an empty password. This is a common pattern for API keys in Basic Auth.

Can I use Bearer token instead?

Stripe's API primarily uses Basic Auth with the API key as the username. Bearer tokens are not the standard for this endpoint.

How do I handle pagination or large responses?

The implementations above fetch the entire response. For large responses, consider streaming or using pagination parameters in the URL.