1
1
import { ClientBuilder , ClientBuilderOptions , Headers , PureRoute } from "../types/builder" ;
2
2
import { Client } from "../types/client" ;
3
- import { BaseRequest , BaseResult , Request , Result } from "../types/http" ;
3
+ import { BaseRequest , BaseResult , HttpMethods , Request , Result } from "../types/http" ;
4
4
5
5
export function createClient < C extends ClientBuilder > ( baseUrl : string , config : C , options ?: ClientBuilderOptions ) : Client < C > {
6
6
const client = { } as Client < C > ;
@@ -71,11 +71,12 @@ export function createClient<C extends ClientBuilder>(baseUrl: string, config: C
71
71
}
72
72
fullPath += path ;
73
73
74
- const url = new URL ( fullPath ) ;
75
74
if ( request . queryParameters ) {
75
+ const url = new URL ( fullPath ) ;
76
76
for ( const [ key , value ] of Object . entries ( request . queryParameters ) ) {
77
77
url . searchParams . append ( key , value . toString ( ) )
78
78
}
79
+ fullPath = url . toString ( )
79
80
}
80
81
81
82
// Auto-apply the JSON Content-Type header if the body is an object.
@@ -87,7 +88,7 @@ export function createClient<C extends ClientBuilder>(baseUrl: string, config: C
87
88
} )
88
89
}
89
90
90
- return fetch ( url . toString ( ) , {
91
+ return fetch ( fullPath , {
91
92
method,
92
93
body : body ?
93
94
(
@@ -112,6 +113,10 @@ export function createClient<C extends ClientBuilder>(baseUrl: string, config: C
112
113
throw e
113
114
}
114
115
return createResult < any > ( {
116
+ request : {
117
+ url : fullPath ,
118
+ method : method as HttpMethods ,
119
+ } ,
115
120
headers : res . headers ,
116
121
statusCode : res . status ,
117
122
data : result ,
0 commit comments