Api class

Simple static API class for HTTP requests.

Usage:

// Configure once
Api.configure(baseUrl: 'https://api.example.com');

// Use anywhere
final posts = await Api.get('/posts');
final post = await Api.post('/posts', body: {'title': 'Hello'});

Constructors

Api()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

clearAuth() → void
Clear authorization header.
configure({String? baseUrl, Map<String, String>? headers, void onError(Object error)?}) → void
Configure the API client.
delete(String path, {Map<String, String>? headers}) Future
DELETE request.
get(String path, {Map<String, String>? headers, Map<String, String>? query}) Future
GET request.
patch(String path, {Object? body, Map<String, String>? headers}) Future
PATCH request.
post(String path, {Object? body, Map<String, String>? headers}) Future
POST request.
put(String path, {Object? body, Map<String, String>? headers}) Future
PUT request.
setAuth(String token, {String type = 'Bearer'}) → void
Set authorization header.