You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/caddy/api-tutorial.md
+13-33Lines changed: 13 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,20 +24,14 @@ This tutorial will show you how to use Caddy's [admin API](https://caddyserver.c
24
24
25
25
To start the Caddy daemon, use the `run` subcommand:
26
26
27
-
```
28
-
caddy run
29
-
```
30
-
27
+
`caddy run`
31
28
This blocks forever, but what is it doing? At the moment... nothing. By default, Caddy's configuration ("config") is blank. We can verify this using the [admin API](https://caddyserver.com/docs/api) in another terminal:
32
29
33
-
```
34
-
curl localhost:2019/config/
35
-
```
36
-
30
+
`curl localhost:2019/config/`
37
31
We can make Caddy useful by giving it a config. One way to do this is by making a POST request to the [/load](https://caddyserver.com/docs/api#post-load) endpoint. Just like any HTTP request, there are many ways to do this, but in this tutorial we'll use `curl`.
38
32
39
-
Your first config[🔗](https://caddyserver.com/docs/api-tutorial#your-first-config"Direct link")
To prepare our request, we need to make a config. Caddy's configuration is simply a [JSON document](https://caddyserver.com/docs/json/) (or [anything that converts to JSON](https://caddyserver.com/docs/config-adapters)).
43
37
@@ -75,10 +69,7 @@ curl localhost:2019/load \
75
69
76
70
We can verify that Caddy applied our new config with another GET request:
77
71
78
-
```
79
-
curl localhost:2019/config/
80
-
```
81
-
72
+
`curl localhost:2019/config/`
82
73
Test that it works by going to [localhost:2015](http://localhost:2015/) in your browser or using `curl`:
83
74
84
75
```
@@ -107,14 +98,11 @@ curl localhost:2019/load \
107
98
108
99
For good measure, verify that the config was updated:
109
100
110
-
```
111
-
curl localhost:2019/config/
112
-
```
113
-
101
+
`curl localhost:2019/config/`
114
102
Test it by refreshing the page in your browser (or running `curl` again), and you will see an inspirational message!
Instead of uploading the entire config file for a small change, let's use a powerful feature of Caddy's API to make the change without ever touching our config file.
120
108
@@ -129,10 +117,7 @@ curl \
129
117
130
118
You can verify that it worked with a similar GET request, for example:
* Don't mix the use of config files with changes via the API; have one source of truth.
146
131
*[Export Caddy's new configuration](https://caddyserver.com/docs/api#get-configpath) with a subsequent GET request (less recommended than the first two options).
147
132
148
-
Using `@id` in JSON[🔗](https://caddyserver.com/docs/api-tutorial#using-id-in-json"Direct link")
Copy file name to clipboardExpand all lines: docs/caddy/architecture.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,8 +43,8 @@ The core of Caddy knows how to work with some of these fields natively:
43
43
44
44
But other top-level fields (like [`apps`](https://caddyserver.com/docs/json/apps/)) are opaque to the core of Caddy. In fact, all Caddy knows to do with the bytes in `apps` is deserialize them into an interface type that it can call two methods on:
45
45
46
-
1.`Start()`
47
-
2.`Stop()`
46
+
1.`Start()`
47
+
2.`Stop()`
48
48
49
49
... and that's it. It calls `Start()` on each app when a config is loaded, and `Stop()` on each app when a config is unloaded.
50
50
@@ -61,10 +61,10 @@ There are two kinds of modules: _host modules_ and _guest modules_.
61
61
62
62
Modules get loaded, are provisioned and validated, get used, then are cleaned up, in this sequence:
63
63
64
-
1. Loaded
65
-
2. Provisioned and validated
66
-
3. Used
67
-
4. Cleaned up
64
+
1.Loaded
65
+
2.Provisioned and validated
66
+
3.Used
67
+
4.Cleaned up
68
68
69
69
Caddy kicks off the module lifecycle when a config is loaded first by initializing all the configured app modules. From there, it's turtles all the way down as each app module takes it the rest of the way.
0 commit comments