From 58eb6d6003ccafb13a18c1601373eb79c28d0f77 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Wed, 4 Jan 2023 16:34:01 +0530 Subject: [PATCH] Update API reference' Signed-off-by: Shubham Sharma --- .../content/en/reference/api/pubsub_api.md | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/daprdocs/content/en/reference/api/pubsub_api.md b/daprdocs/content/en/reference/api/pubsub_api.md index 7b253198b..a7ca07ae0 100644 --- a/daprdocs/content/en/reference/api/pubsub_api.md +++ b/daprdocs/content/en/reference/api/pubsub_api.md @@ -74,30 +74,41 @@ This endpoint lets you publish multiple messages to consumers who are listening POST http://localhost:/v1.0-alpha1/publish/bulk//[?] ``` -The request body should contain a JSON array of entries with unique entry IDs. Example: +The request body should contain a JSON array of entries with unique entry IDs, the event to publish, and the content type of the event. If the content type for an event is not `application/cloudevents+json`, it is auto-wrapped as a CloudEvent (unless `metadata.rawPayload` is set to `true`, see below). -```json -[ - { - "entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002", - "event": "first", - "contentType": "text/plain" - }, - { - "entryId": "b1f40bd6-4af2-11ed-b878-0242ac120002", - "event": { - "message": "second" +Example: + +```bash +curl -X POST http://localhost:3500/v1.0-alpha1/publish/bulk/pubsubName/deathStarStatus \ + -H 'Content-Type: application/json' \ + -d '[ + { + "entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002", + "event": "first", + "contentType": "text/plain" }, - "contentType": "application/json" - }, -] + { + "entryId": "b1f40bd6-4af2-11ed-b878-0242ac120002", + "event": { + "message": "second" + }, + "contentType": "application/json" + }, + ]' ``` -Just like the publish endpoint, the events are auto-wrapped as CloudEvents if `rawPayload` metadata is not set to true. - ### Headers -The `Content-Type` header should be set to `application/json`. +The `Content-Type` header should always be set to `application/json`. + +### URL Parameters + +|**Parameter**|**Description**| +|--|--| +|`daprPort`|The Dapr port| +|`pubsubname`|The name of pubsub component| +|`topic`|The name of the topic| +|`metadata`|Query parameters for metadata as described below| ### Metadata @@ -111,23 +122,25 @@ Metadata can be sent via query parameters in the request's URL. If must be prefi #### HTTP Response -|**Code**|**Description**| +|**HTTP Status**|**Description**| |--|--| |204|All messages delivered| |400|Pubsub does not exist| |403|Forbidden by access controls| |500|At least one message failed to be delivered| -The response body is a JSON containing a list of failed messages. Example: +The response body is a JSON containing a list of failed entries. Example: ```json -[ +{ + "failedEntries": [ { - "entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002", - "error": "error message", - "status": "FAIL", - } -] + "entryId": "ae6bf7c6-4af2-11ed-b878-0242ac120002", + "error": "error message" + }, + ], + "errorCode": "ERR_PUBSUB_PUBLISH_MESSAGE" +} ``` ## Optional Application (User Code) Routes