FormData or URLSearchParams. These utilities handle validation, type conversion, and proper formatting of complex data types.
toFormData
Converts a plain object toFormData, with optional schema validation.
Import
Signature
Parameters
Returns
Returns aFormData object with all entries from the input data.
Behavior
- Primitives (string, number, boolean): Converted to strings
- Blobs/Files: Added directly to FormData
- Arrays: Each item is appended (allows multiple values for same key)
- Objects: JSON stringified before adding to FormData
- Null/Undefined: Skipped
Usage
Basic Usage
With File Uploads
With Arrays
With Nested Objects
With Validation
toSearchParams
Converts a plain object toURLSearchParams, with optional schema validation.
Import
Signature
Parameters
Returns
Returns aURLSearchParams object with all entries from the input data.
Behavior
- Primitives: Converted to strings
- Arrays: Each item is appended as a separate parameter
- Objects: JSON stringified
- Null/Undefined: Skipped
Usage
Basic Usage
With Arrays
In API Calls
With Validation
toQueryString
Converts a plain object directly to a query string.Import
Signature
Usage
Validation Errors
All helper functions throw aValidationError if the schema validation fails:
Common Patterns
File Upload with Metadata
Search with Filters
Validated Form Submission
See Also
- Request Options - Understanding request configuration
- Validation - Schema validation guide
- Error Handling - Working with ValidationError