Code Examples
rpicx API Usage Examples
GET
/v1/healthHealth CheckService health check, returns total image count and running status.
curl 'https://api.tor.hk/v1/v1/health'<script>
fetch('https://api.tor.hk/v1/v1/health')
.then(res => res.json())
.then(data => console.log(data))
</script>fetch('https://api.tor.hk/v1/v1/health')
.then(res => res.json())
.then(data => console.log(data))use reqwest;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<()> {
let resp: Value = reqwest::Client::new()
.get("https://api.tor.hk/v1/v1/health")
.send().await?
.json().await?;
println!("{:?}", resp);
Ok(())
}Response 200:
{
"status": "ok",
"image_count": 100000
}GET
/v1/randomGet Random ImageRandomly selects an image and returns a 302 redirect.
curl 'https://api.tor.hk/v1/v1/random'<img src="https://api.tor.hk/v1/v1/random" alt="Random image" />fetch('https://api.tor.hk/v1/random')
.then(res => res.blob())
.then(blob => {
const img = document.createElement('img')
img.src = URL.createObjectURL(blob)
document.body.appendChild(img)
})use reqwest;
#[tokio::main]
async fn main() -> Result<()> {
let resp = reqwest::get("https://api.tor.hk/v1/random").await?;
let bytes = resp.bytes().await?;
println!("Downloaded {} bytes", bytes.len());
Ok(())
}Success (302):
Location: {siteConfig.image_url}/xxx.webpGET
/v1/categoriesGet CategoriesReturns total image count. Currently flat index, categories is always empty.
curl 'https://api.tor.hk/v1/v1/categories'<script>
fetch('https://api.tor.hk/v1/v1/categories')
.then(res => res.json())
.then(data => console.log(data))
</script>fetch('https://api.tor.hk/v1/v1/categories')
.then(res => res.json())
.then(data => console.log(data))use reqwest;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<()> {
let resp: Value = reqwest::Client::new()
.get("https://api.tor.hk/v1/v1/categories")
.send().await?
.json().await?;
println!("{:?}", resp);
Ok(())
}Response 200:
{
"total_images": 100000,
"categories": []
}GET
/v1/statsGet StatsReturns aggregated service statistics. (IP rate limit 10 QPS, response cache 3h)
curl 'https://api.tor.hk/v1/v1/stats'<script>
fetch('https://api.tor.hk/v1/v1/stats')
.then(res => res.json())
.then(data => console.log(data))
</script>fetch('https://api.tor.hk/v1/v1/stats')
.then(res => res.json())
.then(data => console.log(data))use reqwest;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<()> {
let resp: Value = reqwest::Client::new()
.get("https://api.tor.hk/v1/v1/stats")
.send().await?
.json().await?;
println!("{:?}", resp);
Ok(())
}Response 200:
{
"requests_total": 1000000,
"requests_today": 5000,
"avg_hour_requests": 200.0,
"uv_today": 1200,
"top_referer": [{ "name": "github.com", "count": 300 }],
"top_ua": [{ "name": "Chrome", "count": 500 }],
"status": { "code_200": 900000, "code_302": 50000, "code_404": 20, "code_429": 10, "code_500": 0 },
"sync_count": 30
}GET
/metricsPrometheus MetricsPrometheus metrics endpoint, returns text/plain formatted metrics.
curl 'https://api.tor.hk/v1/metrics'<script>
fetch('https://api.tor.hk/v1/metrics')
.then(res => res.json())
.then(data => console.log(data))
</script>fetch('https://api.tor.hk/v1/metrics')
.then(res => res.text())
.then(data => console.log(data))use reqwest;
#[tokio::main]
async fn main() -> Result<()> {
let resp = reqwest::get("https://api.tor.hk/v1/metrics").await?;
let text = resp.text().await?;
println!("{}", text);
Ok(())
}Response 200:
# HELP rpicx_requests_total Total requests
# TYPE rpicx_requests_total counter
rpicx_requests_total 1000000
# HELP rpicx_images_total Total images
# TYPE rpicx_images_total gauge
rpicx_images_total 100000GET
/openapi.jsonOpenAPI SpecReturns OpenAPI 3.0 specification document (JSON format).
curl 'https://api.tor.hk/v1/openapi.json'<script>
fetch('https://api.tor.hk/v1/openapi.json')
.then(res => res.json())
.then(data => console.log(data))
</script>fetch('https://api.tor.hk/v1/openapi.json')
.then(res => res.json())
.then(data => console.log(data))use reqwest;
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<()> {
let resp: Value = reqwest::Client::new()
.get("https://api.tor.hk/v1/openapi.json")
.send().await?
.json().await?;
println!("{:?}", resp);
Ok(())
}Response 200:
{ "openapi": "3.0.0", "info": { "title": "rpicx API", "version": "1.0.0" } }