Skip to content

Commit

Permalink
feat(client-request.ts): add version parameter to get method and use …
Browse files Browse the repository at this point in the history
…URLSearchParams for query parameters

feat(enums/version.enum.ts): add VERSIONS enum
refactor(client-request.ts): remove unused import statement
remove(constants/versions.ts): remove unused file and export statement
  • Loading branch information
mdwitr0 committed Jun 21, 2023
1 parent 0458aa3 commit ebf90df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/client-request.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { VERSIONS } from './enums/version.enum';

export class ClientRequest {
constructor(
private readonly API_KEY: string,
private readonly API_URL: string,
) {}

async get<T, P>(path: string, params?: P): Promise<T> {
const response = await fetch(`${this.API_URL}${path}`, {
headers: {
'X-API-KEY': this.API_KEY,
async get<T, P>(version: VERSIONS, path: string, params?: P): Promise<T> {
const response = await fetch(
`${this.API_URL}/${version}${path}?${new URLSearchParams(params || {})}`,
{
headers: {
'X-API-KEY': this.API_KEY,
},
},
});
);
return await response.json();
}
}
3 changes: 0 additions & 3 deletions src/constants/versions.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/enums/version.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum VERSIONS {
V1 = 'v1',
V1_1 = 'v1_2',
V1_2 = 'v1.2',
V1_3 = 'v1.3',
}

0 comments on commit ebf90df

Please sign in to comment.