| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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
|