Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}}
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()
}
(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}`)
)
);
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
});
}
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');
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
});
}
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
}),
(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}`));
})();
(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');
}
});
})();
}
}, 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 })
})