Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 5bec68b

Browse files
committed
feat: Allow to use strings as header values
1 parent e16f8e0 commit 5bec68b

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ The `headers` option allows to customize request headers.
145145
const userLoader = createGetEndpoint({
146146
url: keys => `http://example.com/user/${keys.id}`,
147147
headers: {
148-
keys => { "Authorization": `Bearer ${keys.token}` }
148+
Authorization: keys => `Bearer ${keys.token}`,
149+
contentType: "application/json"
149150
}
150151
});
151-
userLoader({id: 9, token: 'YXRvYmF0b2JhdG9i'})
152+
userLoader({ id: 9, token: "YXRvYmF0b2JhdG9i" });
152153
```
153154

154155
## Custom Loaders

core/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ The `headers` option allows to customize request headers.
145145
const userLoader = createGetEndpoint({
146146
url: keys => `http://example.com/user/${keys.id}`,
147147
headers: {
148-
keys => { "Authorization": `Bearer ${keys.token}` }
148+
Authorization: keys => `Bearer ${keys.token}`,
149+
contentType: "application/json"
149150
}
150151
});
151-
userLoader({id: 9, token: 'YXRvYmF0b2JhdG9i'})
152+
userLoader({ id: 9, token: "YXRvYmF0b2JhdG9i" });
152153
```
153154

154155
## Custom Loaders

core/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface EndpointGetOptions<TKeys, TResult, TKeysBind = TKeys>
2020
* A function to create the url
2121
*/
2222
url: (keys: TKeysBind) => string;
23-
headers?: { [keys: string]: (keys: TKeysBind) => string };
23+
headers?: { [keys: string]: string | ((keys: TKeysBind) => string) };
2424
/**
2525
* Wether to cache the request - true by default
2626
*/
@@ -128,7 +128,7 @@ export interface EndpointPostOptions<TKeys, TBody, TResult, TKeysBind = TKeys>
128128
* A function to create the url
129129
*/
130130
url: (keys: TKeysBind) => string;
131-
headers?: { [keys: string]: (keys: TKeysBind) => string };
131+
headers?: { [keys: string]: string | ((keys: TKeysBind) => string) };
132132
/**
133133
* A custom loader
134134
*/
@@ -184,7 +184,7 @@ export interface EndpointPutOptions<TKeys, TBody, TResult, TKeysBind = TKeys>
184184
* A function to create the url
185185
*/
186186
url: (keys: TKeysBind) => string;
187-
headers?: { [keys: string]: (keys: TKeysBind) => string };
187+
headers?: { [keys: string]: string | ((keys: TKeysBind) => string) };
188188
/**
189189
* A custom loader
190190
*/
@@ -240,7 +240,7 @@ export interface EndpointDeleteOptions<TKeys, TResult, TKeysBind = TKeys>
240240
* A function to create the url
241241
*/
242242
url: (keys: TKeysBind) => string;
243-
headers?: { [keys: string]: (keys: TKeysBind) => string };
243+
headers?: { [keys: string]: string | ((keys: TKeysBind) => string) };
244244
/**
245245
* A custom loader
246246
*/

core/src/lib/Endpoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface EndpointOptions<TKeys, TBody, TResult, TKeysBind = TKeys> {
6060
* A function to create the url
6161
*/
6262
url: (keys: TKeysBind) => string;
63-
headers?: { [keys: string]: (keys: TKeysBind) => string };
63+
headers?: { [keys: string]: string | ((keys: TKeysBind) => string) };
6464
/**
6565
* A custom loader
6666
*/

0 commit comments

Comments
 (0)