API文档

本工具提供了简单易用的API接口,可以集成到您的应用程序中用于自动解析和转换curl命令。

API端点

POST /api/convert

使用以下HTTP请求方法和路径访问API:

POST https://curl-to.com/api/convert

请求格式

请求体应该为JSON格式,包含一个`curl`字段,其中包含要解析的curl命令字符串:

请求示例

{
  "curl": "curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{\"name\":\"John\",\"email\":\"[email protected]\"}'"
}

响应格式

响应内容是一个结构化的JSON对象,包含以下字段:

  • method - HTTP请求方法
  • url - 请求URL
  • headers - 请求头
  • data - 请求数据

响应示例

{
  "method": "POST",
  "url": "https://api.example.com/users",
  "headers": {
    "Content-Type": "application/json"
  },
  "data": {
    "name": "John",
    "email": "[email protected]"
  }
}

调用示例

Python

import requests
import json

url = "https://curl-to.com/api/convert"
payload = {
    "curl": "curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{\"name\":\"John\",\"email\":\"[email protected]\"}'"
}

response = requests.post(url, json=payload)
result = response.json()
print(json.dumps(result, indent=2))

JavaScript

const url = 'https://curl-to.com/api/convert';
const payload = {
  curl: `curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name":"John","email":"[email protected]"}'`
};

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(payload),
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

PHP

<?php
$url = 'https://curl-to.com/api/convert';
$payload = [
    'curl' => 'curl -X POST https://api.example.com/users -H \'Content-Type: application/json\' -d \'{"name":"John","email":"[email protected]"}\''
];

$options = [
    'http' => [
        'method'  => 'POST',
        'header'  => 'Content-Type: application/json',
        'content' => json_encode($payload)
    ]
];

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);

print_r($response);
?>