How would I implement automatic query string building? (HttpService)

Hello! I’m planning to make a Notion API SDK (called nu-uh) in Luau, but I can’t figure out how to implement optional query params.

Searched on Google but found nothing.

Here’s my current code:

function nuuh.getUsers(page_size: number?, start_cursor: string?)
	if type(page_size) ~= "number" then
		page_size = 100
	end
	local success
	local response


	success, response = pcall(HttpService:RequestAsync(

		{
			Url = string.format("%s/users/?%d&%s", APILink, page_size, start_cursor),
			Method = "GET",
			Headers = {
				["Authorization"] = "Bearer " .. nuuh.token,
				["Notion-Version"] = APIVersion
			}}
		))
	print(success, response)
	

end

help

2 Likes

Try this

function nuuh.getUsers(page_size: number?, start_cursor: string?, ...)
	if type(page_size) ~= "number" then
		page_size = 100
	end
	local success
	local response


	success, response = pcall(HttpService:RequestAsync(

		{
			Url = string.format("%s/users/?%d&%s", APILink, page_size, start_cursor, ...),
			Method = "GET",
			Headers = {
				["Authorization"] = "Bearer " .. nuuh.token,
				["Notion-Version"] = APIVersion
			}}
		))
	print(success, response)
	

end

Pretty much the … is just extra parameters that can be chosen to be feed to the procedure.

1 Like

Sorry for the late answer but, I didn’t mean that. I meant that I want it so that the & doesn’t appear if there’s no other query.
And also to be able to only declare start_cursor without page_size.
How would I do that?

Bumping this. Please help me make this!

Nvm found one here:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.