@@ -2,7 +2,7 @@ import {ZodType} from "zod";
22import { zodParse } from "@azimutt/models" ;
33import * as Json from "./json" ;
44
5- export const getJson = < Response > ( url : string , zod : ZodType < Response > ) : Promise < Response > => customFetch ( 'GET' , url , undefined , zod )
5+ export const getJson = < Response > ( url : string , zod : ZodType < Response > , headers ?: RequestInit ) : Promise < Response > => customFetch ( 'GET' , url , undefined , zod , headers )
66export const postJson = < Body , Response > ( url : string , body : Body , zod : ZodType < Response > ) : Promise < Response > => customFetch ( 'POST' , url , body , zod )
77export const postNoContent = < Body > ( url : string , body : Body ) : Promise < void > => customFetch ( 'POST' , url , body )
88export const postMultipart = < Response > ( url : string , body : FormData , zod : ZodType < Response > ) : Promise < Response > => customFetch ( 'POST' , url , body , zod )
@@ -12,9 +12,10 @@ export const deleteNoContent = (url: string): Promise<void> => customFetch('DELE
1212
1313type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'
1414
15- function customFetch < Body , Response > ( method : Method , path : string , body ?: Body , zod ?: ZodType < Response > ) : Promise < Response > {
15+ function customFetch < Body , Response > ( method : Method , path : string , body ?: Body , zod ?: ZodType < Response > , headers ?: RequestInit ) : Promise < Response > {
1616 const url = path . startsWith ( 'http' ) ? path : `${ window . location . origin } ${ path } `
17- let opts : RequestInit = path . startsWith ( 'http' ) ? { method} : { method, credentials : 'include' }
17+ let opts : RequestInit = headers ? headers : { }
18+ opts = path . startsWith ( 'http' ) ? { ...opts , method} : { ...opts , method, credentials : 'include' }
1819 if ( body instanceof FormData ) {
1920 opts = { ...opts , body : body }
2021 } else if ( typeof body === 'object' && body !== null ) {
0 commit comments