rest_api_impl 0.0.7 copy "rest_api_impl: ^0.0.7" to clipboard
rest_api_impl: ^0.0.7 copied to clipboard

A Dart package providing a robust REST API IMPL service implementation with HTTP request handling, CRUD operations, and file management.

rest_api_impl #

A Dart package providing a robust REST API service implementation, including HTTP request handling, CRUD operations, and file management.

Features #

  • Dependency injection-based service registration
  • Supports both Dio and Http clients with flexible switching
  • HTTP methods: GET, POST, PUT, PATCH, DELETE
  • Response handling with error management
  • File upload and deletion support
  • Configurable base URL and API key
  • Abstract classes and solid-principled design for extensibility

Installation #

Add the following dependency in your pubspec.yaml file:

dependencies:
  rest_api_impl: latest_version

Usage #

Register Services #

You can register services using either Dio or Http clients:

void main() {
  registerRestApiDataSourceServiceGetItDI(
    clientType: RestApiClientType.dio, // or http
    baseUrl: "https://example.com/api",
    apiKey: "your_api_key_here",
  );
}

Or define static values in constants better security:

void main() {
  registerRestApiDataSourceServiceGetItDI(
    clientType: RestApiClientType.dio, // or http
    baseUrl: RestApiConfigConst.BASE_URL,
    apiKey: RestApiConfigConst.API_KEY,
  );
}

You can also pass custom configurations:

registerRestApiDataSourceServiceGetItDI(
  clientType: RestApiClientType.dio,
  config: DefaultRestApiConfig(
    baseUrl: "https://example.com/api",
    apiKey: "your_api_key_here",
  ),
);

Make API Calls #

CRUD Operations

final restApiService = sl<IRestApiCrudService>();

// Create Data
restApiService.addData(
  endPoint: 'user/create',
  data: {'name': 'John Doe', 'email': 'johndoe@example.com'},
);

// Get Data
restApiService.getData(endPoint: 'user/1');

File Upload

final imageService = sl<IImageServiceRestApiDataSource>();
final file = File('path/to/image.png');

imageService.uploadFile(
  file: file,
  endPoint: 'upload/image',
);

Configuration #

Use the DefaultRestApiConfig to configure base URL and API key:

final config = DefaultRestApiConfig(
  baseUrl: "https://example.com/api",
  apiKey: "your_api_key_here",
);

Or define static values in constants:

class RestApiConfigConst {
  static const BASE_URL = "https://example.com/api";
  static const API_KEY = "your_api_key_here";
}

Contributing #

Contributions are welcome! Please submit issues or pull requests on GitHub.

License #

This project is licensed under the MIT License.

0
likes
140
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package providing a robust REST API IMPL service implementation with HTTP request handling, CRUD operations, and file management.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

cross_file, dio, flutter, get_it_di_global_variable, http, json_annotation, local_data_impl, shared_preferences

More

Packages that depend on rest_api_impl