Skip to content

Commit

Permalink
Allow to set your own headers and your API KEY (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin authored May 8, 2024
1 parent 8c74a9c commit 6c98509
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ import type { paths } from "./gen/types";

export interface CmsClientOptions {
url?: string;
apiKey?: string;
headers?: Record<string, string>;
}

/**
* Open API Fetch client. See docs for usage https://openapi-ts.pages.dev/openapi-fetch/
*/
export function CmsClient(options: CmsClientOptions = {}) {
const { url = "https://cms.cow.fi/api" } = options;
const {
url = "https://cms.cow.fi/api",
headers: baseHeaders = {},
apiKey,
} = options;
return createClient<paths>({
baseUrl: url,
headers: {
...baseHeaders,
...(apiKey
? {
Authorization: "Bearer " + apiKey,
}
: {}),
},
});
}

0 comments on commit 6c98509

Please sign in to comment.