import {AssociativeArray, Connector, HTTP_METHOD} from "../data"; import {$Fetch} from "nitropack"; import {FetchOptions} from "ohmyfetch"; /** * Connector for the ohmyfetch library * * @see https://github.com/unjs/ohmyfetch */ class OhMyFetchConnector implements Connector { private readonly fetch: $Fetch public constructor( fetcher: $Fetch, ) { this.fetch = fetcher } /** * Send an HTTP request * * @param method * @param url * @param body * @param params * @param query */ request( method: HTTP_METHOD, url: string, body: string | null = null, params: AssociativeArray | null = null, query: AssociativeArray | null = null ) { const config: FetchOptions = { body } if (params) { config.params = params } if (query) { config.query = query } return this.fetch(url, config) } } export default OhMyFetchConnector