curl-command-generator
Generates ready-to-run cURL commands from Express, Next.js, Fastify, or other API routes. Creates copy-paste commands with proper headers, authentication, and request bodies. Use when users request "generate curl commands", "curl examples", "api curl", or "command line api testing".
What this skill does
# cURL Command Generator
Generate ready-to-run cURL commands for quick API testing from the command line.
## Core Workflow
1. **Scan routes**: Find all API route definitions
2. **Extract metadata**: Methods, paths, params, bodies
3. **Generate commands**: Create cURL commands with flags
4. **Add authentication**: Bearer, Basic, API Key headers
5. **Include examples**: Request bodies with sample data
6. **Output options**: Markdown, shell script, or plain text
## Basic cURL Syntax
```bash
# GET request
curl -X GET "http://localhost:3000/api/users"
# POST with JSON body
curl -X POST "http://localhost:3000/api/users" \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "[email protected]"}'
# With authentication
curl -X GET "http://localhost:3000/api/users" \
-H "Authorization: Bearer YOUR_TOKEN"
# With query parameters
curl -X GET "http://localhost:3000/api/users?page=1&limit=10"
# Show response headers
curl -i -X GET "http://localhost:3000/api/users"
# Verbose output
curl -v -X GET "http://localhost:3000/api/users"
```
## Generator Script
```typescript
// scripts/generate-curl.ts
import * as fs from "fs";
interface RouteInfo {
method: string;
path: string;
name: string;
description?: string;
body?: object;
queryParams?: { name: string; value: string }[];
auth?: boolean;
}
interface CurlOptions {
baseUrl: string;
authHeader?: string;
verbose?: boolean;
showHeaders?: boolean;
format?: "markdown" | "shell" | "plain";
}
function generateCurlCommand(route: RouteInfo, options: CurlOptions): string {
const parts: string[] = ["curl"];
// Add flags
if (options.verbose) {
parts.push("-v");
}
if (options.showHeaders) {
parts.push("-i");
}
// Method
parts.push(`-X ${route.method}`);
// URL with query params
let url = `${options.baseUrl}${route.path}`;
// Replace path params with placeholders
url = url.replace(/:(\w+)/g, "{$1}");
// Add query params
if (route.queryParams?.length) {
const queryString = route.queryParams
.map((p) => `${p.name}=${p.value}`)
.join("&");
url += `?${queryString}`;
}
parts.push(`"${url}"`);
// Headers
if (["POST", "PUT", "PATCH"].includes(route.method)) {
parts.push('-H "Content-Type: application/json"');
}
if (route.auth && options.authHeader) {
parts.push(`-H "${options.authHeader}"`);
}
// Request body
if (route.body && ["POST", "PUT", "PATCH"].includes(route.method)) {
const bodyJson = JSON.stringify(route.body);
parts.push(`-d '${bodyJson}'`);
}
return parts.join(" \\\n ");
}
function generateCurlCommands(
routes: RouteInfo[],
options: CurlOptions
): string {
const lines: string[] = [];
if (options.format === "markdown") {
lines.push("# API cURL Commands");
lines.push("");
lines.push(`Base URL: \`${options.baseUrl}\``);
lines.push("");
} else if (options.format === "shell") {
lines.push("#!/bin/bash");
lines.push("");
lines.push(`BASE_URL="${options.baseUrl}"`);
lines.push('AUTH_TOKEN="${AUTH_TOKEN:-your-token-here}"');
lines.push("");
}
// Group by resource
const groupedRoutes = groupRoutesByResource(routes);
for (const [resource, resourceRoutes] of Object.entries(groupedRoutes)) {
if (options.format === "markdown") {
lines.push(`## ${capitalize(resource)}`);
lines.push("");
} else if (options.format === "shell") {
lines.push(`# ${capitalize(resource)}`);
lines.push("");
}
for (const route of resourceRoutes) {
if (options.format === "markdown") {
lines.push(`### ${route.name}`);
if (route.description) {
lines.push(route.description);
}
lines.push("");
lines.push("```bash");
} else {
lines.push(`# ${route.name}`);
}
lines.push(generateCurlCommand(route, options));
if (options.format === "markdown") {
lines.push("```");
}
lines.push("");
}
}
return lines.join("\n");
}
function groupRoutesByResource(
routes: RouteInfo[]
): Record<string, RouteInfo[]> {
const groups: Record<string, RouteInfo[]> = {};
for (const route of routes) {
const parts = route.path.split("/").filter(Boolean);
const resource = parts[0] || "api";
if (!groups[resource]) {
groups[resource] = [];
}
groups[resource].push(route);
}
return groups;
}
function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}
```
## Complete Example Output (Markdown)
```markdown
# API cURL Commands
Base URL: `http://localhost:3000/api`
## Authentication
### Login
```bash
curl -X POST "http://localhost:3000/api/auth/login" \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "password123"}'
```
### Register
```bash
curl -X POST "http://localhost:3000/api/auth/register" \
-H "Content-Type: application/json" \
-d '{"name": "New User", "email": "[email protected]", "password": "securepass123"}'
```
## Users
### List Users
```bash
curl -X GET "http://localhost:3000/api/users?page=1&limit=10" \
-H "Authorization: Bearer YOUR_TOKEN"
```
### Get User by ID
```bash
curl -X GET "http://localhost:3000/api/users/{id}" \
-H "Authorization: Bearer YOUR_TOKEN"
```
### Create User
```bash
curl -X POST "http://localhost:3000/api/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"name": "John Doe", "email": "[email protected]", "role": "user"}'
```
### Update User
```bash
curl -X PUT "http://localhost:3000/api/users/{id}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"name": "John Updated", "email": "[email protected]"}'
```
### Delete User
```bash
curl -X DELETE "http://localhost:3000/api/users/{id}" \
-H "Authorization: Bearer YOUR_TOKEN"
```
```
## Shell Script Output
```bash
#!/bin/bash
# api-commands.sh
BASE_URL="${BASE_URL:-http://localhost:3000/api}"
AUTH_TOKEN="${AUTH_TOKEN:-your-token-here}"
# Authentication
# Login
login() {
curl -X POST "${BASE_URL}/auth/login" \
-H "Content-Type: application/json" \
-d "{\"email\": \"$1\", \"password\": \"$2\"}"
}
# Users
# List Users
list_users() {
local page="${1:-1}"
local limit="${2:-10}"
curl -X GET "${BASE_URL}/users?page=${page}&limit=${limit}" \
-H "Authorization: Bearer ${AUTH_TOKEN}"
}
# Get User by ID
get_user() {
curl -X GET "${BASE_URL}/users/$1" \
-H "Authorization: Bearer ${AUTH_TOKEN}"
}
# Create User
create_user() {
curl -X POST "${BASE_URL}/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${AUTH_TOKEN}" \
-d "$1"
}
# Update User
update_user() {
curl -X PUT "${BASE_URL}/users/$1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${AUTH_TOKEN}" \
-d "$2"
}
# Delete User
delete_user() {
curl -X DELETE "${BASE_URL}/users/$1" \
-H "Authorization: Bearer ${AUTH_TOKEN}"
}
# Usage examples:
# ./api-commands.sh
# login [email protected] password123
# list_users 1 10
# get_user abc123
# create_user '{"name": "John", "email": "[email protected]"}'
# update_user abc123 '{"name": "John Updated"}'
# delete_user abc123
# Execute command if provided
if [ -n "$1" ]; then
"$@"
fi
```
## Advanced cURL Flags
```bash
# Common useful flags
curl -X GET "http://localhost:3000/api/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer TOKEN" \
-i # Include response headers
-v # Verbose output
-s # Silent mode (no progress)
-S # Show errors in silent mode
-o response.json # Save response to file
-w "\n%{http_code}\n" # Print status code
--connect-timeout 5 # Connection timeout
--max-time 30 # Max request time
-L Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.