Caddy(8)

πŸ’– caddy-respond β€” the man page but make it slay πŸ’–

okay bestie, welcome to the Caddy manual, section 8 ✨ this one's the respond page, and it's genuinely one of my faves because it's soooo low effort in the best way. sit down, hydrate, let's go 🫢


✨ NAME ✨

caddy-respond β€” simple, hard-coded HTTP responses for development and testing πŸ’…

like. it does ONE thing. and it ate. no cap. πŸŽ€


✨ SYNOPSIS ✨

caddy respond [--status ] [--body ] [--listen ] [--access-log] [--debug]
[--header "Field: value"]  [flags]

(you can also just... pass stuff. we'll get to that, don't worry πŸ™ˆ)


✨ DESCRIPTION ✨

So the whole vibe is: it spins up a quick-and-clean HTTP server for development and testing purposes. that's it. that's the post. πŸ¦‹

With no options specified, this command listens on a random available port and answers HTTP requests with an empty 200 response. iconic. minimalist. she said "no thoughts, head empty, 200 OK".

The listen address can be customized with the --listen flag, and it will always be printed to stdout β€” so don't be sitting there like "what port tho" because it literally tells you, bestie. 😭 If the listen address includes a port range, then multiple servers will be started. yes, plural. she's multitasking. πŸ’…


okay now, the final, unnamed argument situation, because this is the part everyone gets confused about:

If a final, unnamed argument is given, it gets treated as a status code (same as the --status flag) if it is a 3-digit number. Otherwise, it is used as the response body (same as the --body flag).

And here's the plot twist πŸ‘‘: the --status and --body flags will always override this argument. so if you wanna write a body that literally says 404 but with a status code of 200, you do:

--status 200 404

slay. the numbers are lies and that's the point. πŸ“


πŸŽ€ how to give her a body πŸŽ€

A body may be given in 3 ways:

  1. a flag (--body)
  2. a final (and unnamed) argument to the command
  3. piped to stdin β€” but only if flag and argument are unset

Limited template evaluation is supported on the body, with the following variables:

{{.N}}        The server number (useful if using a port range)
{{.Port}}     The listener port
{{.Address}}  The listener address

(no fr, go read the docs for the text/template package in the Go standard library for info about using templates: https://pkg.go.dev/text/template β€” iykyk 🧚)


Also, access/request logging and more verbose debug logging can also be enabled, because sometimes you need to see everything she's thinking. πŸ‘€

And response headers may be added using the --header flag β€” one flag for each header field. πŸ’œ


✨ OPTIONS ✨

  • --access-log[=false] β€” Enable the access log πŸ“
  • -b, --body="" β€” The body of the HTTP response 🫢
  • -v, --debug[=false] β€” Enable more verbose debug-level logging πŸ›
  • -H, --header=[] β€” Set a header on the response (format: "Field: value") πŸŽ€
  • -h, --help[=false] β€” help for respond ❓
  • -l, --listen=":0" β€” The address to which to bind the listener 🌸
  • -s, --status=200 β€” The response status code ✨

✨ SEE ALSO ✨


✨ HISTORY ✨

  • 1-Jan-0001 β€” Auto generated by spf13/cobra πŸ’€

okay that's the whole page, you're basically a Caddy girlie now, no cap πŸ’– if you forget anything just run caddy respond --help and she'll remind you. periodt. 🌈

tiny lil sign-off: this page was Auto generated by spf13/cobra, dated Jan 0001, and it's part of the Caddy(8) manual. bye bestie, go spin up a server πŸ¦‹πŸ’œ
πŸ“¦ where this page comes from