In plain JavaScript, it’s very handy to pass a FormData or URLSearchParams object as body of a XMLHttpRequest.send() or window.fetch() call.
With Tink HTTP client, it seems that the body can only be a haxe.io.Bytes or String object. URLSearchParams objects can be serialized to string with the toString() method, but FormData objects provide no way to serialize them.
Does anyone known if it is possible to use FormData objects, and how, with the Tink HTTP client?
(the compilation target is JavaScript)
That’s not completely true: if the form does not contain any file input, we can use the URLSearchParams constructor (alongside the application/x-www-form-urlencoded content type): see FormData.
import js.Browser.document;
import js.html.*;
final formData = new FormData(cast(document.querySelector("form"), FormElement));
final requestBody = new URLSearchParams(cast formData).toString();
The signature is OK. As usual, thanks a lot @back2dos! That’s exactly what I needed.