post method

Future<Map<String, dynamic>> post(
  1. String url,
  2. Map<String, dynamic> body,
  3. Map<String, String> headers
)
inherited

POSTs body to url and returns the decoded map.

Turns every transport and protocol failure into an AiException carrying a message that names the endpoint, so a wrong base-url is obvious.

Implementation

Future<Map<String, dynamic>> post(
  String url,
  Map<String, dynamic> body,
  Map<String, String> headers,
) async {
  try {
    final response = await _dio.post(
      url,
      data: body,
      options: Options(headers: headers),
    );
    final data = response.data;
    if (data is! Map) {
      throw AiException('$name returned an unexpected response from $url');
    }
    return Map<String, dynamic>.from(data);
  } on DioException catch (e) {
    throw AiException(_describe(e, url));
  }
}