Skip to main content
The Snippets API manages reusable code snippets and command macros for quick terminal insertion.

Overview

Snippets allow you to:
  • Store frequently-used commands and code
  • Share public snippets in marketplace
  • Run snippets with rexec snippets run <name>
  • Categorize by language and tags

List snippets

GET /api/snippets Get all user snippets.
curl
curl https://api.rexec.sh/api/snippets \
  -H "Authorization: Bearer YOUR_TOKEN"
id
string
Snippet ID
name
string
Snippet name
content
string
Code or command content
language
string
Programming language (bash, python, javascript, etc.)
description
string
Optional description
is_public
boolean
Whether visible in marketplace
use_count
integer
Number of times used
created_at
string
ISO timestamp

Create snippet

POST /api/snippets
name
string
required
Snippet name (unique per user)
content
string
required
Code or command content
language
string
Language identifier (default: “bash”)
description
string
Optional description
is_public
boolean
Share in marketplace (default: false)
curl
curl -X POST https://api.rexec.sh/api/snippets \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "docker-cleanup",
    "content": "docker system prune -af && docker volume prune -f",
    "language": "bash",
    "description": "Clean up Docker resources",
    "is_public": true
  }'

Update snippet

PUT /api/snippets/:id Update snippet content or metadata.
curl
curl -X PUT https://api.rexec.sh/api/snippets/snip_123 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "docker system prune -af --volumes",
    "description": "Clean Docker with volumes"
  }'

Delete snippet

DELETE /api/snippets/:id
curl
curl -X DELETE https://api.rexec.sh/api/snippets/snip_123 \
  -H "Authorization: Bearer YOUR_TOKEN"

Increment usage count

POST /api/snippets/:id/use Track snippet usage (called automatically by CLI/UI).
curl
curl -X POST https://api.rexec.sh/api/snippets/snip_123/use \
  -H "Authorization: Bearer YOUR_TOKEN"

Browse marketplace

GET /api/snippets/marketplace List public snippets from all users. Query Parameters:
  • language - Filter by language
  • category - Filter by category
  • search - Search name/description
  • sort - Sort by popular, recent, or name
curl
curl "https://api.rexec.sh/api/snippets/marketplace?language=python&sort=popular" \
  -H "Authorization: Bearer YOUR_TOKEN"

CLI usage

# List snippets
rexec snippets

# Run snippet
rexec snippets run docker-cleanup

# Run with variable substitution
rexec snippets run deploy --var env=production

# Create from stdin
cat setup.sh | rexec snippets create setup-env

Variable substitution

Snippets support template variables:
# Snippet content:
git commit -m "{{message}}" && git push origin {{branch}}

# Run with variables:
rexec snippets run git-push --var message="Fix bug" --var branch=main

Supported languages

  • bash - Shell scripts
  • python - Python code
  • javascript - JavaScript/Node.js
  • typescript - TypeScript
  • go - Go code
  • rust - Rust code
  • sql - SQL queries
  • dockerfile - Dockerfile
  • yaml - YAML config
  • json - JSON data

Build docs developers (and LLMs) love