How to use the ky.post function in ky

To help you get started, we’ve selected a few ky 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 pizzaql / pizzaql / frontend / pages / home.js View on Github external
size: "${values.size}"
								dough: "${values.dough}"
								name: "${values.name}"
								phone: "${values.phone}"
								time: "${values.time}"
								city: "${values.city}"
								street: "${values.street}"
							}
						) {
							id
						}
					}`;

					try {
						// Post a mutation to Prisma and obtain an ID
						const id = await ky.post('http://localhost:4466', {json: {query}}).json();
						const orderID = JSON.stringify(id.data.createOrder.id);
						// Move user to the thank you page
						Router.push({
							pathname: '/order',
							query: {id: orderID}
						});
					} catch (error) {
						console.log(error);
					}

					// Disable double-submission and reset form
					setSubmitting(false);
					resetForm();
				}, 500);
			}}
github system-ui / theme-ui / packages / gatsby-plugin-theme-editor / src / edit.js View on Github external
const save = async e => {
    e.preventDefault()
    setStatus('saving')
    const theme = JSON.stringify(context.theme, null, 2)
    const res = await ky.post('/___theme', {
      json: {
        theme,
      },
    })
    if (!res.ok) setStatus('error')
    else setStatus(null)
    // const text = await res.text()
  }
github zero-to-mastery / mappypals / src / store / actions / auth.js View on Github external
(async () => {
            const url = 'http://localhost:3001/users/login';
            await ky
                .post(url, { json: { email, password } })
                .json()
                .then((res, err) => {
                    if (res.token && res.userId) {
                        setLocalData(res.token, res.userId);
                        dispatch(authLoginSucceeded(res.token, res.userId));
                    } else {
                        // error message here
                        dispatch(authLoginFailed(`Error: ${err.statusText}`));
                    }
                })
                .catch(err =>
                    dispatch(
                        authLoginFailed(`Uncaught Error: ${err.statusText}`)
                    )
                );
github ralscha / blog2019 / ky / client / src / main.js View on Github external
console.log('ky, post multipart/form-data');
  const formData = new FormData();
  formData.append('value1', '10');
  formData.append('value2', 'ten');

  await ky.post('http://localhost:8080/multipart-post', {
    body: formData
  });

  console.log('ky, post application/x-www-form-urlencoded');
  const searchParams = new URLSearchParams();
  searchParams.set('value1', '10');
  searchParams.set('value2', 'ten');

  await ky.post('http://localhost:8080/formurlencoded-post', {
    body: searchParams
  });
}
github ralscha / blog2019 / ky / client / src / main.js View on Github external
console.log('fetch');
  let response = await fetch('http://localhost:8080/simple-post', {
    method: 'POST',
    body: JSON.stringify({ value: "hello world" }),
    headers: {
      'content-type': 'application/json'
    }
  });

  if (response.ok) {
    const body = await response.json();
    console.log(body);
  }

  console.log('ky');
  const body = await ky.post('http://localhost:8080/simple-post', { json: { value: "hello world" } }).json();
  console.log(body);


  console.log('ky, post multipart/form-data');
  const formData = new FormData();
  formData.append('value1', '10');
  formData.append('value2', 'ten');

  await ky.post('http://localhost:8080/multipart-post', {
    body: formData
  });

  console.log('ky, post application/x-www-form-urlencoded');
  const searchParams = new URLSearchParams();
  searchParams.set('value1', '10');
  searchParams.set('value2', 'ten');
github ralscha / blog2019 / ky / client / src / main.js View on Github external
if (response.ok) {
    const body = await response.json();
    console.log(body);
  }

  console.log('ky');
  const body = await ky.post('http://localhost:8080/simple-post', { json: { value: "hello world" } }).json();
  console.log(body);


  console.log('ky, post multipart/form-data');
  const formData = new FormData();
  formData.append('value1', '10');
  formData.append('value2', 'ten');

  await ky.post('http://localhost:8080/multipart-post', {
    body: formData
  });

  console.log('ky, post application/x-www-form-urlencoded');
  const searchParams = new URLSearchParams();
  searchParams.set('value1', '10');
  searchParams.set('value2', 'ten');

  await ky.post('http://localhost:8080/formurlencoded-post', {
    body: searchParams
  });
}
github Tosuke / submarine / src / blocs / authBloc.ts View on Github external
switchMap(async code => {
          const state = 'aaa'
          const json = await ky
            .post(new URL('/oauth/token', endpoint), {
              json: {
                client_id: clientId,
                client_secret: clientSecret,
                code,
                grant_type: 'authorization_code',
                state,
              },
            })
            .json()
          const { access_token } = $.obj({
            access_token: $.string,
            token_type: $.string,
          }).transformOrThrow(json)
          return access_token
        }),
github zero-to-mastery / mappypals / src / pages / Login / Signup.js View on Github external
(async () => {
                const url = process.env.URL || 'http://localhost:3001/';
                await ky
                    .post(`${url}users/register`, { json: this.state })
                    .json()
                    .then((res, err) => {
                        //if error msg is one that we catch
                        if (res.status === 401) {
                            this.setState({ error: String(err.statusText) });
                        } else if (res.status === 200) {
                            this.props.history.push('/login');
                        } else {
                            this.setState({
                                error: `Server Error: Unable to register. Please try again.`
                            });
                        }
                    })
                    .catch(err => alert(`Uncaught Error: ${err.statusText}`));
            })();
github zero-to-mastery / mappypals / src / pages / Login / Signup.js View on Github external
(async () => {
                const url = 'http://localhost:3001/users/register';
                await ky.post(url, { json: this.state }).then(res => {
                    if (res.status === 200) {
                        this.props.history.push('/login');
                    }
                });
            })();
        }
github jalalmostafa / chrome-prayertimes / app / src / common / calculator.ts View on Github external
}, async () => {
                const data = await ky
                    .post(`https://www.googleapis.com/geolocation/v1/geolocate?key=${__GMAPS_API_KEY__}`)
                    .json<{ location: { lat: number; lng: number }, accuracy: number }>()
                const loc: CoordinatesTuple = [data.location.lat, data.location.lng]
                resolve(loc)
            }, { timeout: 2000 })
        })

ky

Tiny and elegant HTTP client based on the Fetch API

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis