El siguiente JSON Stringify no funciona. Me acabo de dar cuenta de que mi solicitud de API debería verse así sin una clave, para que la API se ejecute correctamente.
{[{"resource":"Providers"},{"resource":"ServiceLocation"}]}. // this is the json requesten lugar de esto con la tecla bootStrapInputList.
{"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}¿Cómo creo un encabezado adecuado, sin una clave?
Tipos de datos:
export type BootStrapInput = { resource: string; query?: any; }; export type BootStrapResponse = { status: number; resource: string; body: any; };Servicio:
export const getBootstrap = ( bootStrapInputList: Array<BootStrapInput>, ): any => { return kfetch(`/api/BootStrap`, { method: 'put', body: JSON.stringify({ bootStrapInputList }), }); }; // this json stringify creates {"bootStrapInputList":[{"resource":"Providers"},{"resource":"ServiceLocation"}]}Ejecutar servicio:
(async () => { let bootStrapList: Array<BootStrapInput> = [ { resource: 'Providers' }, { resource: 'ServiceLocation' }, ]; const datatest = await getBootstrap(bootStrapList); // this is not working correctlyCreo que lo que realmente quieres es hacer lo siguiente en el servicio:
body: JSON.stringify({ ...bootStrapInputList }),Esa línea debería dar como resultado:
{[{"resource":"Providers"},{"resource":"ServiceLocation"}]}Vi el comentario jsN00b y mientras dijiste que funcionó y, por supuesto, te creo y estoy feliz de que lo hayas resuelto, pero haciendo:
body: JSON.stringify( bootStrapInputList ),resultaría en:
[{"resource":"Providers"},{"resource":"ServiceLocation"}]Lo cual no es lo mismo (ningún objeto envuelve la matriz).
¡Buena suerte!