#!/usr/bin/env bash # post3 usage with raw curl commands # # Prerequisites: # post3-server running: mise run up && mise run dev # # Usage: # bash examples/curl.sh # # Or: # mise run example:curl set -euo pipefail BASE="http://localhost:9000" BUCKET="curl-demo" echo "=== post3 curl Demo ===" # Create a bucket (PUT /{bucket}) echo "" echo "--- Creating bucket '$BUCKET'" curl -s -X PUT "$BASE/$BUCKET" -o /dev/null -w "HTTP %{http_code}\n" # List buckets (GET /) echo "" echo "--- Listing buckets" curl -s "$BASE/" | head -20 echo "" # Put an object (PUT /{bucket}/{key}) echo "" echo "--- Putting hello.txt" curl -s -X PUT "$BASE/$BUCKET/hello.txt" \ -d "Hello from curl!" \ -H "Content-Type: text/plain" \ -o /dev/null -w "HTTP %{http_code}\n" # Put with custom metadata (x-amz-meta-* headers) echo "" echo "--- Putting report.txt with metadata" curl -s -X PUT "$BASE/$BUCKET/report.txt" \ -d "Report content" \ -H "Content-Type: text/plain" \ -H "x-amz-meta-author: bob" \ -H "x-amz-meta-version: 3" \ -o /dev/null -w "HTTP %{http_code}\n" # Get an object (GET /{bucket}/{key}) echo "" echo "--- Getting hello.txt" curl -s "$BASE/$BUCKET/hello.txt" echo "" # Head an object (HEAD /{bucket}/{key}) echo "" echo "--- Head report.txt" curl -s -I "$BASE/$BUCKET/report.txt" # List objects (GET /{bucket}?list-type=2) echo "" echo "--- Listing objects" curl -s "$BASE/$BUCKET?list-type=2" | head -20 echo "" # List with prefix echo "" echo "--- Putting docs/readme.md" curl -s -X PUT "$BASE/$BUCKET/docs/readme.md" -d "# README" -o /dev/null -w "HTTP %{http_code}\n" echo "--- Listing with prefix 'docs/'" curl -s "$BASE/$BUCKET?list-type=2&prefix=docs/" | head -20 echo "" # Delete objects (DELETE /{bucket}/{key}) echo "" echo "--- Cleaning up" curl -s -X DELETE "$BASE/$BUCKET/hello.txt" -o /dev/null -w "DELETE hello.txt: HTTP %{http_code}\n" curl -s -X DELETE "$BASE/$BUCKET/report.txt" -o /dev/null -w "DELETE report.txt: HTTP %{http_code}\n" curl -s -X DELETE "$BASE/$BUCKET/docs/readme.md" -o /dev/null -w "DELETE docs/readme.md: HTTP %{http_code}\n" # Delete bucket (DELETE /{bucket}) curl -s -X DELETE "$BASE/$BUCKET" -o /dev/null -w "DELETE bucket: HTTP %{http_code}\n" echo "" echo "=== Done ==="