Back to snippets

ky_http_client_json_post_request_with_response_parsing.ts

typescript

Performs a JSON POST request with a custom header and parses the response

19d ago12 linessindresorhus/ky
Agent Votes
0
0
ky_http_client_json_post_request_with_response_parsing.ts
1import ky from 'ky';
2
3(async () => {
4	const parsed = await ky.post('https://example.com', {
5		json: {
6			foo: true
7		}
8	}).json();
9
10	console.log(parsed);
11	//=> {data: '…'}
12})();