|
67 | 67 | Here's an example showing how to publish a message using <tt>curl</tt> (via POST):
|
68 | 68 | </p>
|
69 | 69 | <code>
|
70 |
| - curl -d "Backup successful 😀" ntfy.sh/mytopic |
| 70 | + curl -d "Backup successful 😀" <span class="ntfyUrl">ntfy.sh</span>/mytopic |
71 | 71 | </code>
|
72 | 72 | <p class="smallMarginBottom">
|
73 | 73 | And another one using PUT:
|
74 | 74 | </p>
|
75 | 75 | <code>
|
76 |
| - echo -en "\u26A0\uFE0F Unauthorized login" | curl -sT- ntfy.sh/mytopic |
| 76 | + echo -en "\u26A0\uFE0F Unauthorized login" | curl -sT- <span class="ntfyUrl">ntfy.sh</span>/mytopic |
77 | 77 | </code>
|
78 | 78 | <p class="smallMarginBottom">
|
79 | 79 | Here's an example in JS with <tt>fetch()</tt> (see <a href="https://github.com/binwiederhier/ntfy/tree/main/examples">full example</a>):
|
80 | 80 | </p>
|
81 | 81 | <code>
|
82 |
| - fetch('https://ntfy.sh/mytopic', {<br/> |
| 82 | + fetch('https://<span class="ntfyUrl">ntfy.sh</span>/mytopic', {<br/> |
83 | 83 | method: 'POST', // PUT works too<br/>
|
84 | 84 | body: 'Hello from the other side.'<br/>
|
85 | 85 | })
|
|
127 | 127 | notifications like this (see <a href="example.html">live example</a>):
|
128 | 128 | </p>
|
129 | 129 | <code>
|
130 |
| - const eventSource = new EventSource('https://ntfy.sh/mytopic/sse');<br/> |
| 130 | + const eventSource = new EventSource('<span class="ntfyProtocol">https://</span><span class="ntfyUrl">ntfy.sh</span>/mytopic/sse');<br/> |
131 | 131 | eventSource.onmessage = (e) => {<br/>
|
132 | 132 | // Do something with e.data<br/>
|
133 | 133 | };
|
|
136 | 136 | You can also use the same <tt>/sse</tt> endpoint via <tt>curl</tt> or any other HTTP library:
|
137 | 137 | </p>
|
138 | 138 | <code>
|
139 |
| - $ curl -s ntfy.sh/mytopic/sse<br/> |
| 139 | + $ curl -s <span class="ntfyUrl">ntfy.sh</span>/mytopic/sse<br/> |
140 | 140 | event: open<br/>
|
141 | 141 | data: {"id":"weSj9RtNkj","time":1635528898,"event":"open","topic":"mytopic"}<br/><br/>
|
142 | 142 |
|
|
149 | 149 | To consume JSON instead, use the <tt>/json</tt> endpoint, which prints one message per line:
|
150 | 150 | </p>
|
151 | 151 | <code>
|
152 |
| - $ curl -s ntfy.sh/mytopic/json<br/> |
| 152 | + $ curl -s <span class="ntfyUrl">ntfy.sh</span>/mytopic/json<br/> |
153 | 153 | {"id":"SLiKI64DOt","time":1635528757,"event":"open","topic":"mytopic"}<br/>
|
154 | 154 | {"id":"hwQ2YpKdmg","time":1635528741,"event":"message","topic":"mytopic","message":"Hi!"}<br/>
|
155 | 155 | {"id":"DGUDShMCsc","time":1635528787,"event":"keepalive","topic":"mytopic"}
|
|
158 | 158 | Or use the <tt>/raw</tt> endpoint if you need something super simple (empty lines are keepalive messages):
|
159 | 159 | </p>
|
160 | 160 | <code>
|
161 |
| - $ curl -s ntfy.sh/mytopic/raw<br/> |
| 161 | + $ curl -s <span class="ntfyUrl">ntfy.sh</span>/mytopic/raw<br/> |
162 | 162 | <br/>
|
163 | 163 | This is a notification<br/>
|
164 | 164 | And another one with a smiley face 😀
|
|
173 | 173 | cached messages).
|
174 | 174 | </p>
|
175 | 175 | <code>
|
176 |
| - curl -s "ntfy.sh/mytopic/json?since=10m" |
| 176 | + curl -s "<span class="ntfyUrl">ntfy.sh</span>/mytopic/json?since=10m" |
177 | 177 | </code>
|
178 | 178 |
|
179 | 179 | <h3 id="polling" class="anchor">Polling (<tt>poll=1</tt>)</h3>
|
|
183 | 183 | combined with <tt>since=</tt> (defaults to <tt>since=all</tt>).
|
184 | 184 | </p>
|
185 | 185 | <code>
|
186 |
| - curl -s "ntfy.sh/mytopic/json?poll=1" |
| 186 | + curl -s "<span class="ntfyUrl">ntfy.sh</span>/mytopic/json?poll=1" |
187 | 187 | </code>
|
188 | 188 |
|
189 | 189 | <h3 id="multiple-topics" class="anchor">Subscribing to multiple topics (<tt>topic1,topic2,...</tt>)</h3>
|
|
192 | 192 | comma-separated list of topics in the URL. This allows you to reduce the number of connections you have to maintain:
|
193 | 193 | </p>
|
194 | 194 | <code>
|
195 |
| - $ curl -s ntfy.sh/mytopic1,mytopic2/json<br/> |
| 195 | + $ curl -s <span class="ntfyUrl">ntfy.sh</span>/mytopic1,mytopic2/json<br/> |
196 | 196 | {"id":"0OkXIryH3H","time":1637182619,"event":"open","topic":"mytopic1,mytopic2,mytopic3"}<br/>
|
197 | 197 | {"id":"dzJJm7BCWs","time":1637182634,"event":"message","topic":"mytopic1","message":"for topic 1"}<br/>
|
198 | 198 | {"id":"Cm02DsxUHb","time":1637182643,"event":"message","topic":"mytopic2","message":"for topic 2"}
|
|
214 | 214 | <code>
|
215 | 215 | rsync -a root@laptop /backups/laptop \<br/>
|
216 | 216 | && zfs snapshot ... \<br/>
|
217 |
| - && curl -d "Laptop backup succeeded" ntfy.sh/backups \<br/> |
218 |
| - || echo -en "\u26A0\uFE0F Laptop backup failed" | curl -sT- ntfy.sh/backups |
| 217 | + && curl -d "Laptop backup succeeded" <span class="ntfyUrl">ntfy.sh</span>/backups \<br/> |
| 218 | + || echo -en "\u26A0\uFE0F Laptop backup failed" | curl -sT- <span class="ntfyUrl">ntfy.sh</span>/backups |
219 | 219 | </code>
|
220 | 220 |
|
221 | 221 | <h3 id="example-web" class="anchor">Example: Server-sent messages in your web app</h3>
|
|
242 | 242 | <code>
|
243 | 243 | #!/bin/bash<br/>
|
244 | 244 | if [ "${PAM_TYPE}" = "open_session" ]; then<br/>
|
245 |
| - echo -en "\u26A0\uFE0F SSH login: ${PAM_USER} from ${PAM_RHOST}" | curl -T- ntfy.sh/alerts<br/> |
| 245 | + echo -en "\u26A0\uFE0F SSH login: ${PAM_USER} from ${PAM_RHOST}" | curl -T- <span class="ntfyUrl">ntfy.sh</span>/alerts<br/> |
246 | 246 | fi
|
247 | 247 | </code>
|
248 | 248 |
|
|
254 | 254 | <code>
|
255 | 255 | while read result; do<br/>
|
256 | 256 | [ -n "$result" ] && echo "$result" >> results.csv<br/>
|
257 |
| - done < <(stdbuf -i0 -o0 curl -s ntfy.sh/results/raw) |
| 257 | + done < <(stdbuf -i0 -o0 curl -s <span class="ntfyUrl">ntfy.sh</span>/results/raw) |
258 | 258 | </code>
|
259 | 259 |
|
260 | 260 | <h2 id="faq" class="anchor">FAQ</h2>
|
|
331 | 331 | To send notifications to it, simply PUT or POST to the topic URL. Here's an example using <tt>curl</tt>:
|
332 | 332 | </p>
|
333 | 333 | <code>
|
334 |
| - curl -d "Backup failed" <span id="detailTopicUrl"></span> |
| 334 | + curl -d "Backup failed" <span id="detailTopicUrl">ntfy.sh/topic</span> |
335 | 335 | </code>
|
336 | 336 | <p id="detailNotificationsDisallowed">
|
337 | 337 | If you'd like to receive desktop notifications when new messages arrive on this topic, you have
|
|
0 commit comments