ApiBody class

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

This class is platform-agnostic and works on mobile, desktop and web. File uploads are referenced either by a file-system String path (mobile/desktop only) or by raw bytes (all platforms, including web).

Usage examples:

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

// Form data with files (path is mobile/desktop only)
ApiBody.formData(
  fields: {'title': 'My Post'},
  files: [ApiFile(fieldName: 'image', path: 'path/to/image.jpg')],
)

// Form data with bytes (works everywhere, incl. web)
ApiBody.formData(
  files: [ApiFile(fieldName: 'image', bytes: imageBytes, filename: 'i.jpg')],
)

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

// GraphQL
ApiBody.graphQL(
  query: 'query { users { id name } }',
  variables: {'limit': 10},
)

// Binary file by path (mobile/desktop)
ApiBody.binaryFile('path/to/file.pdf')

// Binary bytes (works everywhere, incl. web)
ApiBody.binaryBytes(bytes, 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, String? binaryFilePath, List<int>? binaryBytes, String? binaryMimeType})
const
ApiBody.binaryBytes(List<int> bytes, {String? mimeType})
Binary upload from raw bytes.
const
ApiBody.binaryFile(String path, {String? mimeType})
Binary file upload from a file-system path (mobile/desktop only).
const
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 with query and optional 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 to JSON.
const
ApiBody.text(String text)
Plain text body.
const
ApiBody.urlEncoded(Map<String, String> fields)
application/x-www-form-urlencoded body.
const
ApiBody.xml(String xml)
XML body.
const

Properties

binaryBytes List<int>?
final
binaryFilePath String?
File-system path for a binary upload. Mobile/desktop only — on web the file is read at request-build time and will throw. Use binaryBytes on web instead.
final
binaryMimeType String?
final
fields Map<String, String>?
final
files List<ApiFile>?
final
graphQLQuery String?
final
graphQLVariables Map<String, dynamic>?
final
hashCode int
The hash code for this object.
no setterinherited
rawContentType RawBodyContentType
final
rawData → dynamic
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type ApiBodyType
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