Qaynaq LABS · TOOLS

CURL → CODE · GET · BEARER

cURL → 10 languages

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

Source cURL
curl -X GET https://api.stripe.com/v1/payouts/po_1234567890 \
  -H "Authorization: Bearer sk_test_1234567890" \
  -H "Stripe-Version: 2023-10-16"

Python · requests

import os
import requests

response = requests.get(
    "https://api.stripe.com/v1/payouts/po_1234567890",
    headers={
        "Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
        "Stripe-Version": "2023-10-16"
    }
)
response.raise_for_status()
print(response.json())

Python · httpx

import os
import httpx

with httpx.Client() as client:
    response = client.get(
        "https://api.stripe.com/v1/payouts/po_1234567890",
        headers={
            "Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
            "Stripe-Version": "2023-10-16"
        }
    )
    response.raise_for_status()
    print(response.json())

Node.js · fetch

import fetch from 'node-fetch';

const response = await fetch('https://api.stripe.com/v1/payouts/po_1234567890', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
    'Stripe-Version': '2023-10-16'
  }
});

if (!response.ok) {
  throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();
console.log(data);

Node.js · axios

import axios from 'axios';

const response = await axios.get('https://api.stripe.com/v1/payouts/po_1234567890', {
  headers: {
    'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
    'Stripe-Version': '2023-10-16'
  }
});

console.log(response.data);

Go · net/http

package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
)

func main() {
	client := &http.Client{}
	req, err := http.NewRequest(
		"GET",
		"https://api.stripe.com/v1/payouts/po_1234567890",
		nil,
	)
	if err != nil {
		log.Fatal(err)
	}

	req.Header.Set("Authorization", "Bearer "+os.Getenv("STRIPE_SECRET_KEY"))
	req.Header.Set("Stripe-Version", "2023-10-16")

	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		body, _ := io.ReadAll(resp.Body)
		log.Fatalf("HTTP error! status: %d, body: %s", resp.StatusCode, body)
	}

	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}

PHP · cURL

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/payouts/po_1234567890');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . getenv('STRIPE_SECRET_KEY'),
    'Stripe-Version: 2023-10-16'
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    die('Error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
    die("HTTP error! status: $httpCode, body: $response");
}

header('Content-Type: application/json');
echo $response;

curl_close($ch);

Ruby · net/http

require 'net/http'
require 'json'

uri = URI('https://api.stripe.com/v1/payouts/po_1234567890')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{ENV['STRIPE_SECRET_KEY']}"
req['Stripe-Version'] = '2023-10-16'

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(req)
end

unless res.is_a?(Net::HTTPSuccess)
  raise "HTTP error! status: #{res.code}, body: #{res.body}"
end

puts JSON.parse(res.body)

Swift · URLSession

import Foundation

let url = URL(string: "https://api.stripe.com/v1/payouts/po_1234567890")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("2023-10-16", forHTTPHeaderField: "Stripe-Version")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        fatalError("Error: \(error)")
    }
    guard let httpResponse = response as? HTTPURLResponse else {
        fatalError("Invalid response")
    }
    guard (200...299).contains(httpResponse.statusCode) else {
        fatalError("HTTP error! status: \(httpResponse.statusCode)")
    }
    if let data = data, let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] {
        print(json)
    }
}
task.resume()
RunLoop.main.run()

Rust · reqwest

use reqwest;
use std::env;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = reqwest::Client::new();
    let response = client
        .get("https://api.stripe.com/v1/payouts/po_1234567890")
        .header("Authorization", format!("Bearer {}", env::var("STRIPE_SECRET_KEY").unwrap()))
        .header("Stripe-Version", "2023-10-16")
        .send()
        .await?;

    if !response.status().is_success() {
        panic!("HTTP error! status: {}", response.status());
    }

    let body = response.json::<serde_json::Value>().await?;
    println!("{:?}", body);
    Ok(())
}

C# · HttpClient

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

class Program
{
    static async Task Main()
    {
        var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Get, "https://api.stripe.com/v1/payouts/po_1234567890");
        request.Headers.Add("Authorization", $"Bearer {Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY")}");
        request.Headers.Add("Stripe-Version", "2023-10-16");

        var response = await client.SendAsync(request);
        if (!response.IsSuccessStatusCode)
        {
            throw new Exception($"HTTP error! status: {response.StatusCode}");
        }

        var content = await response.Content.ReadAsStringAsync();
        Console.WriteLine(content);
    }
}

Translation notes

  • All implementations read the Stripe secret key from an environment variable named STRIPE_SECRET_KEY
  • Error handling is minimal but includes status code checks and body reading where applicable
  • JSON responses are parsed into native objects/dictionaries where the library supports it
  • Headers are set using the idiomatic method for each language
  • The Stripe-Version header is preserved exactly as in the original cURL command

Common pitfalls when porting

  • Forgetting to set the STRIPE_SECRET_KEY environment variable before running the code
  • Not handling potential network errors (timeouts, DNS failures, etc.)
  • Assuming the response body is always JSON without checking the Content-Type header
  • In languages with async/await, forgetting to await the request can lead to unhandled promises/futures
  • In Go, not closing the response body can lead to resource leaks

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 use environment variables for secrets instead of hardcoding?

Environment variables are a secure way to handle secrets as they are not committed to version control and can be managed separately from the codebase.

How do I set the STRIPE_SECRET_KEY environment variable?

In Unix-like systems: `export STRIPE_SECRET_KEY=sk_test_1234567890`; in Windows: `set STRIPE_SECRET_KEY=sk_test_1234567890`.

What if I need to use a different Stripe API version?

Change the Stripe-Version header value to the desired API version string, e.g., '2023-11-15'.

How can I add query parameters to the request?

Append them to the URL, e.g., `https://api.stripe.com/v1/payouts?limit=10`.