HttpClassicTransformer class

Classic response transformer

The following structures can be processed:

{
  code: <int>,
  message: <String>,
  data: <AnyType>
}

Example:

var http = Http.getInstances(HttpBaseOptions({
  name: 'defaultApi',
  baseUrl: 'http://domain.com/api/v1',
  transformer: HttpClassicTransformer(
    codeKey: 'code',
    messageKey: 'message',
    dataKey: 'data',
  ),
}));
var res = await http.get('/users');
print(res.data); // "res.data" is "response.data[dataKey]" for Dio

If you want to get the raw data, please use the "isRaw" parameter:

var res = await http.get('/download/music.mp3', HttpOptions(
  extra: {'isRaw': true}
));
print(res.data); // "res.data" in "response.data" for Dio

HttpError will be thrown when an error occurs.

Inheritance

Constructors

HttpClassicTransformer({int successCode = 0, String codeKey = 'code', String messageKey = 'message', String dataKey = 'data'})

Properties

codeKey String
final
dataKey String
final
hashCode int
The hash code for this object.
no setterinherited
messageKey String
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
successCode int
final

Methods

errorHandler(DioError err) HttpError
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
transformer<T>(Response<T> response) Future<Response<T>>
override

Operators

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