Skip to content

Commit 08c1592

Browse files
committed
[Queues] Addd an example to demo HTTP Push
1 parent c7e0ad5 commit 08c1592

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Publish to a Queue via HTTP
3+
summary: Publish to a Queue directly via HTTP.
4+
pcx_content_type: example
5+
sidebar:
6+
order: 31
7+
head:
8+
- tag: title
9+
content: Queues - Publish Directly via HTTP
10+
description: Publish to a Queue directly via HTTP and Workers.
11+
---
12+
13+
The following example shows you how to publish messages to a Queue from any HTTP client, using a Cloudflare API token to authenticate.
14+
15+
This allows you to write to a Queue from any service or programming language that supports HTTP, including Go, Rust, Python or even a Bash script.
16+
17+
### Prerequisites
18+
19+
- A [queue created](/queues/get-started/#3-create-a-queue) via the [Cloudflare dashboard](https://dash.cloudflare.com) or the [wrangler CLI](/workers/wrangler/install-and-update/).
20+
- A Cloudflare API token with the `Queues Edit` permission.
21+
22+
23+
### 1. Send a test message
24+
25+
To make sure you successfully authenticate and write a message to your queue, use `curl` on the command line:
26+
27+
```sh
28+
# Make sure to replace the placeholder with your shared secret
29+
curl -XPOST -H "Authorization: Bearer <paste-your-api-token-here>" "https://api.cloudflare.com/client/v4/accounts/<paste-your-account-id-here>/queues/<paste-your-queue-id-here>/messages" --data '{ "body": { "greeting": "hello" } }'
30+
```
31+
32+
```sh output
33+
{"success":true}
34+
```
35+
36+
This will issue a HTTP POST request, and if successful, return a HTTP 200 with a `success: true` response body.
37+
38+
- If you receive a HTTP 403, this is because your API token is invalid or does not have the `Queues Edit` permission.
39+
40+
For full documentation about the HTTP Push API, refer to the [Cloudflare API documentation](https://developers.cloudflare.com/api/resources/queues/subresources/messages/).

0 commit comments

Comments
 (0)