|
| 1 | +--- |
| 2 | +title: HTTP |
| 3 | +pcx_content_type: concept |
| 4 | +sidebar: |
| 5 | + order: 1 |
| 6 | +head: |
| 7 | + - tag: title |
| 8 | + content: HTTP |
| 9 | +--- |
| 10 | + |
| 11 | +import { Render, PackageManagers } from "~/components"; |
| 12 | + |
| 13 | +You can send data to your Pipeline via HTTP. By default, HTTP is enabled on all Pipelines. When you create a Pipeline, it will generate an HTTP endpoint †hat you can make POST requests to. |
| 14 | + |
| 15 | +```sh |
| 16 | +$ npx wrangler pipelines create [PIPELINE-NAME] --r2 [R2-BUCKET-NAME] --access-key-id [ACCESS-KEY-ID] --secret-access-key [SECRET-ACCESS-KEY] |
| 17 | + |
| 18 | +🌀 Creating pipeline named "[PIPELINE-NAME]" |
| 19 | +✅ Successfully created pipeline [PIPELINE-NAME] with ID [PIPELINE-ID] |
| 20 | + |
| 21 | +You can now send data to your pipeline with: |
| 22 | + curl "https://<PIPELINE-ID>.pipelines.cloudflare.com/" -d '[{ ...JSON_DATA... }]' |
| 23 | +``` |
| 24 | + |
| 25 | +## Turning HTTP off |
| 26 | +By default, ingestion via HTTP is turned on for all Pipelines. You can turn it off by setting `--http false` when creating or updating a Pipeline. |
| 27 | + |
| 28 | +```sh |
| 29 | +$ npx wrangler pipelines create [PIPELINE-NAME] --r2 [R2-BUCKET-NAME] --access-key-id [ACCESS-KEY-ID] --secret-access-key [SECRET-ACCESS-KEY] --http false |
| 30 | +``` |
| 31 | + |
| 32 | +Ingestion URLs are tied to your Pipeline ID. Turning HTTP off, and then turning it back on, will not change the URL. |
| 33 | + |
| 34 | +## Authentication |
| 35 | +You can secure your HTTP ingestion endpoint using Cloudflare API tokens. By default, authentication is turned off. To enable authentication, use `--authentication true` while creating or updating a Pipeline. |
| 36 | + |
| 37 | +``` |
| 38 | +$ npx wrangler pipelines create [PIPELINE-NAME] --r2 [R2-BUCKET-NAME] --access-key-id [ACCESS-KEY-ID] --secret-access-key [SECRET-ACCESS-KEY] --authentication true |
| 39 | +``` |
| 40 | + |
| 41 | +Once authentication is turned on, you will need to include a Cloudflare API token in your request headers. |
| 42 | + |
| 43 | +### Get API token |
| 44 | +1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account. |
| 45 | +2. Navigate to your [API Keys](https://dash.cloudflare.com/profile/api-tokens) |
| 46 | +3. Select *Create Token* |
| 47 | +4. Choose the template for Workers Pipelines. Click on *continue to summary*, and finally on *create token*. Make sure to copy the API token, and save it securely. |
| 48 | + |
| 49 | +### Making authenticated requests |
| 50 | +Include the API token you created in the previous step in the headers for your request: |
| 51 | + |
| 52 | +```sh |
| 53 | +curl https://<PIPELINE-ID>.pipelines.cloudflare.com |
| 54 | + -H "Content-Type: application/json" \ |
| 55 | + -H "Authorization: Bearer ${API_TOKEN}" \ |
| 56 | + -d '[ |
| 57 | + {"key1": "value1", "key2": "value2"}, |
| 58 | + {"key1": "value3", "key2": "value4"} |
| 59 | + ]' |
| 60 | +``` |
0 commit comments