ApiClient class

A lightweight HTTP client wrapper for handling RESTful API requests.

The ApiClient class provides convenient methods to perform standard HTTP operations such as GET, POST, PUT, DELETE, and Multipart POST requests.

It includes built-in JSON encoding, logging, and response handling through a centralized exception manager (handleException).

This client is primarily used throughout the google_map_service package to interact with Google Maps Platform APIs and other backend services.

Example usage:

final client = ApiClient(baseUrl: "https://maps.googleapis.com/maps");

final result = await client.get(
  "/api/place/details/json",
  params: {"place_id": "ChIJN1t_tDeuEmsRUsoyG83frY4", "key": "YOUR_KEY"},
);
print(result);

Constructors

ApiClient({required String baseUrl, Client? client})
Creates a new ApiClient with the given baseUrl.

Properties

baseUrl String
The base URL for all requests (e.g., "https://maps.googleapis.com/maps").
final
hashCode int
The hash code for this object.
no setterinherited
httpClient → Client
The HTTP client used to send network requests. Defaults to a new instance of http.Client if not provided.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String endpoint, {Map<String, String>? headers, Object? body}) Future
Sends a DELETE request to the specified endpoint.
get(String endpoint, {Map<String, String>? headers, Map<String, dynamic>? params}) Future
Sends a GET request to the specified endpoint.
multiPartPost(String endpoint, {Map<String, String>? headers, Map<String, String>? body, Iterable<MultipartFile>? multipartFiles}) Future
Sends a multipart POST request to the given endpoint.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post(String endpoint, {Map<String, String>? headers, Object? body}) Future
Sends a POST request to the specified endpoint.
put(String endpoint, {Map<String, String>? headers, Object? body}) Future
Sends a PUT request to the specified endpoint.
toString() String
A string representation of this object.
inherited

Operators

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