| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /**
- * A basic api request service
- *
- * It will send basic http requests and returns raw results
- */
- import { $Fetch, FetchOptions } from "ohmyfetch";
- class ApiRequestService {
- private readonly fetch: $Fetch;
- public constructor(fetch: $Fetch) {
- this.fetch = fetch;
- }
- /**
- * Send a GET request
- *
- * @param url
- * @param query
- */
- public async get<T>(
- url: string,
- query: AssociativeArray | null = null
- ): Promise<T> {
- return await this.request<T>("GET", url, null, query);
- }
- protected async request<T>(
- method: string,
- url: string,
- body: string | null = null,
- query: AssociativeArray | null = null
- ): Promise<T> {
- const config: FetchOptions = { method };
- if (query) {
- config.query = query;
- }
- // @ts-ignore
- return this.fetch<T>(url, config);
- }
- }
- export default ApiRequestService;
|