How to use the ky-universal.post function in ky-universal

To help you get started, we’ve selected a few ky-universal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vadimdemedes / draqula / src / Draqula.ts View on Github external
const execute = async (): Promise => {
			try {
				const response: any = await ky
					.post(this.url, {
						json: {
							query: this.createQuery(query),
							variables
						},
						signal: options.signal,
						hooks: this.options.hooks,
						timeout: options.timeout || this.options.timeout
					})
					.json();

				// GraphQL servers don't fail the request, even if resolvers are failing
				// They still return 200 status code, but add `errors` field in the response
				if (Array.isArray(response.errors)) {
					const errors = response.errors.map((error: any) => {
						const error2 = new Error(error.message) as any;
github Ovyerus / micro-link / pages / add.tsx View on Github external
const submit = React.useCallback(async () => {
    if (badUrl) return;

    setResult(null);
    setError(null);

    let result: APIResponse;

    try {
      result = await ky
        .post('shorten', {
          prefixUrl: location.origin,
          json: { url, code }
        })
        .json();
    } catch (err) {
      const b = await err.response.json();

      console.log(b);
      console.error(err);
      setError(err);
      return;
    }

    setResult(result.url);
  }, [badUrl, code, url]);
github Ovyerus / micro-link / pages / index.tsx View on Github external
const submit = React.useCallback(async () => {
    if (!key) return;

    setError(null);

    try {
      await ky.post('auth', {
        prefixUrl: location.origin,
        json: { key }
      });
      router.push('/add');
    } catch (err) {
      console.error(err);
      setError(err);
    }
  }, [key, router]);
github saltyshiomix / ark / lib / http / index.ts View on Github external
public async post(url: string, data?: any): Promise {
    return ky.post(url, { prefixUrl, json: data }).json();
  }