DD
DevDash

URL Encode for REST APIs — Query String Encoding

Quick Answer: REST API query parameters must be URL-encoded. For arrays, use repeated keys (ids=1&ids=2) or bracket notation (ids[]=1&ids[]=2) depending on the API. For nested objects, use dot or bracket notation as documented by the specific API.

FAQ

How do I pass arrays in REST API query params?

Three common conventions: repeated keys (ids=1&ids=2), brackets (ids[]=1&ids[]=2), or comma-separated (ids=1,2). Check the API documentation for the expected format.

Should I use URLSearchParams?

Yes. In JavaScript, new URLSearchParams({key: "val"}).toString() handles encoding correctly. It also handles arrays with append(): params.append("id", "1"); params.append("id", "2").

Want API access + no ads? Pro coming soon.