ApiBody class

Holds request body data for all Postman-style body types.

Examples

// JSON body
ApiBody.json({'email': 'a@b.com', 'password': '123456'})

// Plain text
ApiBody.text('Hello world')

// XML
ApiBody.xml('<root><id>1</id></root>')

// Form data with text fields + file upload
ApiBody.formData(
  fields: {'title': 'My Post', 'category': 'news'},
  files: [
    ApiFile(fieldName: 'avatar', file: File('/path/to/photo.jpg')),
  ],
)

// URL-encoded
ApiBody.urlEncoded({'grant_type': 'password', 'username': 'admin'})

// GraphQL
ApiBody.graphQL(
  query: 'query GetUser(\$id: ID!) { user(id: \$id) { name email } }',
  variables: {'id': '42'},
)

// Binary file
ApiBody.binaryFile(File('/path/to/report.pdf'), mimeType: 'application/pdf')

Constructors

ApiBody({ApiBodyType type = ApiBodyType.none, dynamic rawData, RawBodyContentType rawContentType = RawBodyContentType.json, Map<String, String>? fields, List<ApiFile>? files, String? graphQLQuery, Map<String, dynamic>? graphQLVariables, File? binaryFile, List<int>? binaryBytes, String? binaryMimeType})
Creates an ApiBody with full control over every field.
const
ApiBody.binaryBytes(List<int> bytes, {String? mimeType})
Binary upload from raw bytes (web-compatible).
const
ApiBody.binaryFile(File file, {String? mimeType})
Binary file upload from a File object (mobile/desktop).
ApiBody.formData({Map<String, String>? fields, List<ApiFile>? files})
multipart/form-data with optional text fields and file attachments.
const
ApiBody.graphQL({required String query, Map<String, dynamic>? variables})
GraphQL body — serialized as {"query": "...", "variables": {...}}.
const
ApiBody.html(String html)
HTML body.
const
ApiBody.javascript(String js)
JavaScript body.
const
ApiBody.json(dynamic data)
JSON body — pass a Map or List; auto-encoded with jsonEncode.
const
ApiBody.text(String text)
Plain-text body.
const
ApiBody.urlEncoded(Map<String, String> fields)
application/x-www-form-urlencoded — URL-encoded key/value pairs.
const
ApiBody.xml(String xml)
XML body.
const

Properties

binaryBytes List<int>?
Raw bytes for ApiBodyType.binary bodies (web-compatible).
final
binaryFile File?
File for ApiBodyType.binary bodies.
final
binaryMimeType String?
MIME type for ApiBodyType.binary bodies. Defaults to application/octet-stream.
final
fields Map<String, String>?
Text fields for ApiBodyType.formData and ApiBodyType.xWwwFormUrlencoded bodies.
final
files List<ApiFile>?
File attachments for ApiBodyType.formData bodies.
final
graphQLQuery String?
GraphQL query string for ApiBodyType.graphQL bodies.
final
graphQLVariables Map<String, dynamic>?
GraphQL variables for ApiBodyType.graphQL bodies.
final
hashCode int
The hash code for this object.
no setterinherited
rawContentType RawBodyContentType
Content-type for ApiBodyType.raw bodies. Defaults to JSON.
final
rawData → dynamic
Raw body data for ApiBodyType.raw.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type ApiBodyType
The body type that determines how data is encoded and sent.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited