Skip to content

Commit

Permalink
add get, post, patch, delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesthl committed Mar 26, 2023
1 parent 037eb82 commit 7148fa2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import { AxiosDigestAuth } from '@lukesthl/ts-axios-digest-auth';

interface Response {}

const digestAuth = new AxiosDigestAuth({
const digestAuthClient = new AxiosDigestAuth({
username: MY_DIGEST_USERNAME,
password: MY_DIGEST_PASSWORD,
});

await digestAuth.request<Response>({
headers: { Accept: 'application/json' },
method: 'GET',
url: 'https://example.com',
});
await digestAuthClient.get('https://example.com');
```

## API
Expand All @@ -50,7 +46,6 @@ Type: `string`
##### axios (optional)

Type: `AxiosInstance`
Optional

## Special Thanks

Expand Down
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@ export class AxiosDigestAuth {
);
}

public async get<T>(
url: string,
config?: AxiosRequestConfig<T>
): Promise<AxiosResponse<T, unknown>> {
return this.request<T>({ url, method: 'GET', ...config });
}

public async post<T>(
url: string,
data: T,
config?: AxiosRequestConfig<T>
): Promise<AxiosResponse<T, unknown>> {
return this.request<T>({ url, method: 'GET', data, ...config });
}

public async put<T>(
url: string,
data: T,
config?: AxiosRequestConfig<T>
): Promise<AxiosResponse<T, unknown>> {
return this.request<T>({ url, method: 'PUT', data, ...config });
}

public async delete<T>(
url: string,
config?: AxiosRequestConfig<T>
): Promise<AxiosResponse<T, unknown>> {
return this.request<T>({ url, method: 'DELETE', ...config });
}

public async request<T>(
opts: AxiosRequestConfig
): Promise<AxiosResponse<T, unknown>> {
Expand Down
6 changes: 1 addition & 5 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ describe('index', () => {
password: PASSWORD,
username: USERNAME,
});
await digestAuth.request({
headers: { Accept: 'application/json' },
method: 'GET',
url: 'https://cloud.mongodb.com/api/atlas/v1.0/groups',
});
await digestAuth.get('https://cloud.mongodb.com/api/atlas/v1.0/groups');
});
});
});

0 comments on commit 7148fa2

Please sign in to comment.