body option, ofetch will:
- Stringify it to JSON
- Set the
content-typeheader toapplication/json - Set the
acceptheader toapplication/json
Basic Usage
Content-Type Detection
ofetch only auto-stringifies when the content is JSON-serializable and you haven’t set a differentcontent-type:
What Gets Stringified?
ofetch considers a value JSON-serializable if it’s:- A plain object (
{}) - An array (
[]) - A primitive (string, number, boolean, null)
- An object with a
.toJSON()method
FormData- sent as-isURLSearchParams- sent as-isBlob- sent as-isArrayBuffer/ typed arrays - sent as-isReadableStream- sent as-is
toJSON() Support
If your object has a.toJSON() method, ofetch will automatically call it:
Form URL Encoded
You can send form-encoded data by setting the content-type:Type Definition
Fromsrc/types.ts:27:
RequestInit body type, or a plain object/array that will be automatically stringified.