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/products \
  -H "Authorization: Bearer sk_test_1234567890" \
  -H "Content-Type: application/json"

Python · requests

import os
import requests

response = requests.get(
    "https://api.stripe.com/v1/products",
    headers={
        "Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
        "Content-Type": "application/json"
    }
)
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/products",
        headers={
            "Authorization": f"Bearer {os.environ['STRIPE_SECRET_KEY']}",
            "Content-Type": "application/json"
        }
    )
    response.raise_for_status()
    print(response.json())

Node.js · fetch

import fetch from 'node-fetch';

const response = await fetch('https://api.stripe.com/v1/products', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
    'Content-Type': 'application/json'
  }
});

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/products', {
  headers: {
    'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
    'Content-Type': 'application/json'
  }
});

console.log(response.data);

Go · net/http

package main

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

func main() {
	req, err := http.NewRequest("GET", "https://api.stripe.com/v1/products", nil)
	if err != nil {
		panic(err)
	}

	req.Header.Set("Authorization", "Bearer "+os.Getenv("STRIPE_SECRET_KEY"))
	req.Header.Set("Content-Type", "application/json")

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

	if resp.StatusCode != http.StatusOK {
		panic(fmt.Sprintf("HTTP error! status: %s", resp.Status))
	}

	// Read and print response body
	// (omitted for brevity; use io.ReadAll in real code)
}

PHP · cURL

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/products');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . getenv('STRIPE_SECRET_KEY'),
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    throw new Exception('Curl error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
    throw new Exception("HTTP error! status: $httpCode");
}

$data = json_decode($response, true);
print_r($data);

curl_close($ch);
?>

Ruby · net/http

require 'net/http'
require 'json'

uri = URI('https://api.stripe.com/v1/products')

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri)
request['Authorization'] = "Bearer #{ENV['STRIPE_SECRET_KEY']}"
request['Content-Type'] = 'application/json'

response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
  raise "HTTP error! status: #{response.code}"
end

puts JSON.parse(response.body)

Swift · URLSession

import Foundation

let url = URL(string: "https://api.stripe.com/v1/products")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer \(ProcessInfo.processInfo.environment["STRIPE_SECRET_KEY"] ?? "")", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let error = error {
        fatalError("Error: \(error)")
    }
    guard let httpResponse = response as? HTTPURLResponse,
          (200...299).contains(httpResponse.statusCode) else {
        fatalError("HTTP error! status: \((response as? HTTPURLResponse)?.statusCode ?? 0)")
    }
    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/products")
        .header("Authorization", format!("Bearer {}", env::var("STRIPE_SECRET_KEY").unwrap()))
        .header("Content-Type", "application/json")
        .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();
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY")}");
        client.DefaultRequestHeaders.Add("Content-Type", "application/json");

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

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

Translation notes

  • All implementations use environment variables for secrets (STRIPE_SECRET_KEY).
  • Python uses requests/httpx, Node.js uses fetch/axios, Go uses net/http, PHP uses cURL, Ruby uses Net::HTTP, Swift uses URLSession, Rust uses reqwest, C# uses HttpClient.
  • Error handling is minimal but includes status code checks and basic error propagation.
  • Headers are preserved exactly as in the cURL command.
  • No request body is sent with GET requests.

Common pitfalls when porting

  • Forgetting to set the STRIPE_SECRET_KEY environment variable before running the code.
  • Not handling HTTP errors properly (e.g., ignoring status codes).
  • In Rust, forgetting to enable the 'tokio' runtime or 'reqwest' async features.
  • In Swift, not running the task in a run loop (e.g., in a command-line tool).
  • In Go, not closing the response body (use defer resp.Body.Close()).
  • In PHP, not checking for cURL errors after execution.

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 them?

Environment variables are a secure way to handle secrets. They avoid exposing sensitive data in source code or version control systems.

How do I install the required dependencies for each language?

Python: `pip install requests httpx`; Node.js: `npm install node-fetch axios`; Go: `go get` (no additional setup); PHP: built-in; Ruby: built-in; Swift: built-in; Rust: add `reqwest` and `tokio` to Cargo.toml; C#: built-in with .NET SDK.

Can I use a different HTTP client library?

Yes, but ensure it supports the same features (e.g., headers, environment variables for secrets). The examples use idiomatic libraries for each language.