Sending JSON Body with `HttpClientRequest` Instead of `Uint8Array`
With the
here's what my code looks like, but it's sending the actual body as a Uint8Array rather than a json string.
HttpClientRequestHttpClientRequest, is there a way when the request is sent to send the body as a json string instead of a Uint8Array?here's what my code looks like, but it's sending the actual body as a Uint8Array rather than a json string.
// This is just a quick snippet of the code, all of this is within a Effect.gen
const client = yield* HttpClient.HttpClient;
const decodedInput = yield* Schema.decodeUnknown(inputSchema)(
input || {},
);
const routes = Ajax.Window.ShopifyRoutes.make();
const route = routes[routeName];
const url = `${window.location.origin}${route}`;
let request: HttpClientRequest.HttpClientRequest;
if (method === "post") {
request = yield* HttpClientRequest.post(url, {
acceptJson: true,
headers: {
"X-SDK-Variant": "brytdesigns",
"X-SK-Variant-Source": "shopify-cart-ajax-api",
},
}).pipe(HttpClientRequest.bodyJson(decodedInput));
} else if (method === "get") {
request = HttpClientRequest.get(url, {
acceptJson: true,
}).pipe(HttpClientRequest.setUrlParams(decodedInput));
} else {
return yield* Effect.fail(new InvalidAjaxMethodError());
}// This is just a quick snippet of the code, all of this is within a Effect.gen
const client = yield* HttpClient.HttpClient;
const decodedInput = yield* Schema.decodeUnknown(inputSchema)(
input || {},
);
const routes = Ajax.Window.ShopifyRoutes.make();
const route = routes[routeName];
const url = `${window.location.origin}${route}`;
let request: HttpClientRequest.HttpClientRequest;
if (method === "post") {
request = yield* HttpClientRequest.post(url, {
acceptJson: true,
headers: {
"X-SDK-Variant": "brytdesigns",
"X-SK-Variant-Source": "shopify-cart-ajax-api",
},
}).pipe(HttpClientRequest.bodyJson(decodedInput));
} else if (method === "get") {
request = HttpClientRequest.get(url, {
acceptJson: true,
}).pipe(HttpClientRequest.setUrlParams(decodedInput));
} else {
return yield* Effect.fail(new InvalidAjaxMethodError());
}