responseParser property

ResponseParser responseParser
final

响应解析器(可选,默认使用 StandardResponseParser) 用于将原始 HTTP 响应(RawHttpResponse)转换为用户定义的 Response

如果不提供,将使用默认的 StandardResponseParser(处理标准结构:{code: int, message: String, data: dynamic})

可以使用 PathBasedResponseParser 来支持不同路径使用不同解析器

示例:

// 使用默认解析器(不传递 responseParser)
HttpConfig(baseUrl: 'https://api.example.com')

// 或自定义解析器
responseParser: StandardResponseParser()

或使用路径匹配:

responseParser: PathBasedResponseParser(
  matchers: [
    PathMatcher(pattern: RegExp(r'^/api/v1/.*'), parser: V1Parser()),
    PathMatcher(pattern: RegExp(r'^/api/v2/.*'), parser: V2Parser()),
  ],
  defaultParser: StandardResponseParser(),
)

Implementation

final ResponseParser responseParser;