Skip to content

Commit

Permalink
Unify rawPayload message docs
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Dec 6, 2024
1 parent 0879255 commit c26ddea
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 37 deletions.
14 changes: 8 additions & 6 deletions csharp/Svix/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ public Message(ISvixClient svixClient, IMessageApi messageApi)
_messageApi = messageApi ?? throw new ArgumentException(nameof(messageApi));
}


/// <summary>Creates a [MessageIn] with the payload already being serialized.
/// <summary>Creates a [MessageIn] with a pre-serialized payload.
/// <para>
/// The payload is not normalized on the server (usually whitespace outside
/// of string literals, unnecessarily escaped characters in string and such
/// are fixed up by the server), and is not even required to be JSON.
/// The payload is not normalized on the server. Normally, payloads are
/// required to be JSON, and Svix will minify the payload before sending the
/// webhooks (for example, by removing extraneous whitespace or unnecessarily
/// escaped characters in strings). With this function, the payload will be
/// sent "as is", without any minification or other processing.
/// </para>
/// </summary>
/// <param name="payload">Serialized message payload</param>
/// <param name="contentType">Content type of the payload to send as a header. Defaults to `application/json`.</param>
/// <param name="contentType">The `content-type` header of the webhook sent by Svix,
/// overwriting the default of `application/json` if specified</param>
public static MessageIn messageInRaw(
string eventType,
string payload,
Expand Down
15 changes: 8 additions & 7 deletions java/lib/src/main/java/com/svix/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ private static MessageIn messageInEmptyPayload() {
}

/**
* Creates a MessageIn with the payload already being serialized.
* Creates a MessageIn with a pre-serialized payload.
*
* The payload is not normalized on the server (usually whitespace outside
* of string literals, unnecessarily escaped characters in string and such
* are fixed up by the server). The default Content-Type of application/json
* is used. See the other overload if you want to send non-JSON payloads.
* The payload is not normalized on the server. Normally, payloads are
* required to be JSON, and Svix will minify the payload before sending the
* webhooks (for example, by removing extraneous whitespace or unnecessarily
* escaped characters in strings). With this function, the payload will be
* sent "as is", without any minification or other processing.
*
* @param payload Serialized message payload
*/
Expand All @@ -41,12 +42,12 @@ public static MessageIn messageInRaw(final String payload) {
}

/**
* Creates a MessageIn with the payload already being serialized.
* Creates a MessageIn with a pre-serialized payload.
*
* This overload is intended for non-JSON payloads.
*
* @param payload Serialized message payload
* @param contentType The value to use for the Content-Type header
* @param contentType The value to use for the Content-Type header of the webhook sent by Svix
*/
public static MessageIn messageInRaw(final String payload, final String contentType) {
HashMap<String, Object> trParam = new HashMap<>();
Expand Down
12 changes: 7 additions & 5 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,16 @@ class Message {
}

/**
* Creates a `MessageIn` with the payload already being serialized.
* Creates a `MessageIn` with a pre-serialized payload.
*
* The payload is not normalized on the server (usually whitespace outside
* of string literals, unnecessarily escaped characters in string and such
* are fixed up by the server), and is not even required to be JSON.
* The payload is not normalized on the server. Normally, payloads are
* required to be JSON, and Svix will minify the payload before sending the
* webhooks (for example, by removing extraneous whitespace or unnecessarily
* escaped characters in strings). With this function, the payload will be
* sent "as is", without any minification or other processing.
*
* @param payload Serialized message payload
* @param contentType Content type of the payload to send as a header. Defaults to `application/json`.
* @param contentType The value to use for the Content-Type header of the webhook sent by Svix, overwriting the default of `application/json` if specified
*
* See the class documentation for details about the other parameters.
*/
Expand Down
13 changes: 7 additions & 6 deletions kotlin/lib/src/main/kotlin/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ class Message internal constructor(token: String, options: SvixOptions) {
}

/**
* Creates a [MessageIn] with the payload already being serialized.
* Creates a [MessageIn] with a pre-serialized payload.
*
* The payload is not normalized on the server (usually whitespace outside
* of string literals, unnecessarily escaped characters in string and such
* are fixed up by the server), and is not even required to be JSON.
* The payload is not normalized on the server. Normally, payloads are
* required to be JSON, and Svix will minify the payload before sending the
* webhooks (for example, by removing extraneous whitespace or unnecessarily
* escaped characters in strings). With this function, the payload will be
* sent "as is", without any minification or other processing.
*
* @param payload Serialized message payload
* @param contentType Content type of the payload to send as a header. Defaults to `application/json`.
* @param contentType The value to use for the Content-Type header of the webhook sent by Svix, overwriting the default of `application/json` if specified
*
* See the class documentation for details about the other parameters.
*
*/
fun messageInRaw(
eventType: String,
Expand Down
7 changes: 4 additions & 3 deletions python/svix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def message_in_raw(
event_type: str, payload: str, content_type: t.Optional[str] = None
) -> MessageIn:
"""
Creates a `MessageIn` with the payload already being serialized.
Creates a `MessageIn` with a pre-serialized payload.
The payload is not normalized on the server. Normally, payloads are required
to be JSON, and Svix will minify the payload before sending the webhook
Expand All @@ -1177,8 +1177,9 @@ def message_in_raw(
Args:
event_type (str): The event type's name Example: `user.signup`.
payload (str): Serialized message payload.
content_type (str?): The `content-type` header value Svix uses for
the webhook request. If not specified, `application/json` is used.
content_type (str?): The value to use for the Content-Type header of the
webhook sent by Svix, overwriting the default of `application/json`
if specified.
"""
transformations_params: t.Dict[str, t.Any] = {
"rawPayload": payload,
Expand Down
8 changes: 4 additions & 4 deletions ruby/lib/svix/message_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def expunge_content(app_id, msg_id)
end
end

# Creates a [`MessageIn`] with the payload already being serialized.
# Creates a [`MessageIn`] with a pre-serialized payload.
#
# The payload is not normalized on the server. Normally, payloads are required
# to be JSON, and Svix will minify the payload before sending the webhook
Expand All @@ -34,9 +34,9 @@ def expunge_content(app_id, msg_id)
# "as is", without any minification or other processing.
#
# `attributes[:payload]` must be a string. An extra attribute `content_type`
# is accepted that sets the `content-type` header of the webhook, overwriting
# the default of `application/json` if specified. Other than that, the
# attributes are forwarded [`MessageIn.new`], so all the same ones are
# is accepted that sets the `content-type` header of the webhook sent by Svix,
# overwriting the default of `application/json` if specified. Other than that,
# the attributes are forwarded [`MessageIn.new`], so all the same ones are
# accepted.
def message_in_raw(attributes = {})
attributes[:transformations_params] ||= {}
Expand Down
16 changes: 10 additions & 6 deletions rust/src/model_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ use crate::models::MessageIn;
impl MessageIn {
/// Create a new message with a pre-serialized payload.
///
/// The payload is not normalized on the server (usually whitespace outside
/// of string literals, unnecessarily escaped characters in string and such
/// are fixed up by the server), and is not even required to be JSON.
/// The payload is not normalized on the server. Normally, payloads are
/// required to be JSON, and Svix will minify the payload before sending
/// the webhook (for example, by removing extraneous whitespace or
/// unnecessarily escaped characters in strings). With this constructor,
/// the payload will be sent "as is", without any minification or other
/// processing.
///
/// The default `content-type` of `application/json` will still be used,
/// unless overwritten with [`with_content_type`][Self::with_content_type].
/// The default `content-type` of `application/json` will still be used for
/// the webhook sent by Svix, unless overwritten with
/// [`with_content_type`][Self::with_content_type].
pub fn new_raw_payload(event_type: String, payload: String) -> Self {
Self {
transformations_params: Some(json!({ "rawPayload": payload })),
..Self::new(event_type, json!({}))
}
}

/// Set the `content-type` header to use for the message.
/// Set the `content-type` header to use for the webhook sent by Svix.
pub fn with_content_type(mut self, content_type: String) -> Self {
let transformations_params = self.transformations_params.get_or_insert_with(|| json!({}));

Expand Down

0 comments on commit c26ddea

Please sign in to comment.