API quick-start

    • Basic terminal / command line skills
    • and curl in your PATH

    First start Caddy:

    Caddy is currently running idle (with a blank configuration). Give it a simple config with curl:

    1. curl localhost:2019/load \
    2. -X POST \
    3. -H "Content-Type: application/json" \
    4. -d @- << EOF
    5. {
    6. "apps": {
    7. "http": {
    8. "listen": [":2015"],
    9. "routes": [
    10. {
    11. "handle": [{
    12. "handler": "static_response",
    13. "body": "Hello, world!"
    14. }]
    15. }
    16. ]
    17. }
    18. }
    19. }
    20. EOF

    Now load localhost:2015 in your browser or use curl:

    1. curl localhost:2015
    2. Hello, world!

    We can also define multiple sites on different interfaces with this JSON:

    Try out your new “goodbye” endpoint or with curl to make sure it works:

    1. curl localhost:2016

    When you are done with Caddy, make sure to stop it: