From e483aebae454d5fb5d69dff0d8536b453353f306 Mon Sep 17 00:00:00 2001 From: Filip Hoffmann Date: Sat, 31 May 2025 12:14:17 +0200 Subject: [PATCH] switch multipart request to only accept json --- src/grom/internal/rest.gleam | 8 ++++++-- test/grom_test.gleam | 14 ++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/grom/internal/rest.gleam b/src/grom/internal/rest.gleam index 9a4e07d..4a942c8 100644 --- a/src/grom/internal/rest.gleam +++ b/src/grom/internal/rest.gleam @@ -3,6 +3,7 @@ import gleam/http/request.{type Request} import gleam/http/response.{type Response} import gleam/httpc import gleam/int +import gleam/json.{type Json} import gleam/list import gleam/option.{type Option, None, Some} import gleam/result @@ -58,7 +59,7 @@ pub fn new_multipart_request( client: Client, method: http.Method, path: String, - payload_json: String, + payload_json: Json, files: List(File), ) { let #(_, file_parts) = @@ -76,7 +77,10 @@ pub fn new_multipart_request( [ #( "payload_json", - field.StringWithType(payload_json, "application/json"), + field.StringWithType( + payload_json |> json.to_string, + "application/json", + ), ), ], file_parts, diff --git a/test/grom_test.gleam b/test/grom_test.gleam index e10a670..69b7920 100644 --- a/test/grom_test.gleam +++ b/test/grom_test.gleam @@ -41,10 +41,16 @@ pub fn multipart_request_test() { ) let result = - rest.new_multipart_request(client.Client("token"), http.Post, "/", "{}", [ - File("name", "image/png", <<"test":utf8>>), - File("name2", "image/jpeg", <<"jpeg":utf8>>), - ]) + rest.new_multipart_request( + client.Client("token"), + http.Post, + "/", + json.object([]), + [ + File("name", "image/png", <<"test":utf8>>), + File("name2", "image/jpeg", <<"jpeg":utf8>>), + ], + ) result |> should.equal(expected) -- 2.51.2