headersFromInstance static method

Map<String, String> headersFromInstance(
  1. Object instance
)

Add request headers

Implementation

static Map<String, String> headersFromInstance(Object instance) {
  Map<String, String> headers = {'Accept': 'application/json'};

  /// Add bearer token
  if (instance is Authenticate && ClouxConfig.bearerToken != null) {
    headers['Authorization'] = 'Bearer ${ClouxConfig.bearerToken!}';
  } else if (instance is Authenticate && ClouxConfig.bearerToken == null) {
    throw NotBearerTokenAvailableException();
  }

  return headers;
}