Skip to content

A CLI tool that reads JSON from stdin, transforms it using expressions, and sends HTTP requests.

Notifications You must be signed in to change notification settings

octoberswimmer/pub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pub

A CLI tool that reads JSON from stdin, transforms it using expressions, and sends HTTP requests.

Installation

go install github.com/octoberswimmer/pub@latest

Or build from source:

go build -o pub

Usage

pub [flags] <URL expression>

Flags

  • --transform <expression> - Transform the input JSON before sending
  • --header <expression> - Add HTTP headers (can be used multiple times)
  • --request <method> - HTTP method (default: POST)
  • --dry-run - Print requests without sending them

Expression Language

All expressions have access to:

  • input - The current JSON line being processed
  • env - Environment variables (including those from .env file)

Examples

Basic Usage

Send JSON as-is to an endpoint:

echo '{"message": "hello"}' | pub "http://localhost:8080/webhook"

Transform Input

Wrap input in a data field:

echo '{"id": 123}' | pub --transform '{data: input}' "http://localhost:8080/api"

Dynamic URLs

Use input fields in the URL:

echo '{"queue": "urgent", "id": 123}' | pub '"http://localhost:8080/publish?queue=" + input.queue'

Headers with Environment Variables

Add authorization header from environment:

echo '{"data": "test"}' | pub \
  --header '"Authorization: Bearer " + env.API_TOKEN' \
  "http://api.example.com/endpoint"

Multiple Headers

echo '{"data": "test"}' | pub \
  --header '"Authorization: Bearer " + env.TOKEN' \
  --header '"X-Request-ID: " + input.id' \
  --request PUT \
  "http://api.example.com/resource"

Dry Run Mode

See what would be sent without making requests:

echo '{"test": "data"}' | pub --dry-run \
  --transform '{wrapped: input}' \
  --header '"Content-Type: application/json"' \
  "http://localhost:8080/test"

Real-world Example

Process Salesforce platform events:

force pubsub subscribe /event/My_Event__e | pub \
  --transform '{data: input}' \
  --header '"Authorization: Bearer " + env.EVENTS_PUBLISH_TOKEN' \
  --request POST \
  '"http://localhost:8080/publish?queue=" + input.Queue_Name__c'

Environment Variables

Create a .env file in your working directory:

API_TOKEN=your-secret-token
API_ENDPOINT=https://api.example.com

These will be automatically loaded and available as env.API_TOKEN and env.API_ENDPOINT in expressions.

Processing Multiple Lines

The tool processes JSON line by line, making a separate HTTP request for each valid JSON line:

# Process multiple events
cat events.jsonl | pub --transform '{event: input}' "http://localhost:8080/ingest"

Empty lines are skipped. Invalid JSON lines will log an error and continue processing.

Error Handling

  • HTTP errors (status >= 400) are logged but processing continues
  • JSON parsing errors are logged per line
  • Expression evaluation errors are logged with details
  • The tool exits with status 1 if stdin reading fails

About

A CLI tool that reads JSON from stdin, transforms it using expressions, and sends HTTP requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages