Skip to content
Discussion options

You must be logged in to vote

you can get the rendered URL in a few ways:

after the request completes:

const response = await got('https://example.com', {
	searchParams: {foo: 'bar', baz: 'qux'}
});

console.log(response.requestUrl.toString());
// => https://example.com?foo=bar&baz=qux

console.log(response.url);
// => final URL as string (after redirects)

before the request is sent (to debug encoding):

await got('https://example.com', {
	searchParams: {foo: 'bar baz'},
	hooks: {
		beforeRequest: [
			options => {
				console.log(options.url.toString());
				// => https://example.com?foo=bar+baz
			}
		]
	}
});

the beforeRequest hook is the best way to see exactly whats being sent, including how searchParams are encoded.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1808 on July 27, 2021 10:13.