Laravel REST API – Flutter

A Flutter package that provides a clean, typed integration between your Flutter app and a Laravel REST API backend: custom HTTP client, repositories, search, mutations, deletes, and custom actions.

Terminal
 flutter pub add laravel_rest_api_flutter
GIF
Build to be easy
Built to be truly plug-and-play, this package focuses on simplicity and efficiency — configure a client, define your models, and start talking to your Laravel REST API.
Highly modular
Designed to do more with less — start simple, keep it light, and add only the repositories and endpoints you need. A minimal, modular foundation that grows with your project.
A lot of Compatibility
Optimized for seamless integration with any Laravel REST API and your existing Flutter stack. Swap HTTP clients, adjust headers, or extend repositories without changing your UI.

First Steps

Installation Guide

Quick installation setup.

Terminal
 flutter pub add laravel_rest_api_flutter
pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
  laravel_rest_api_flutter: any
  dio: any # or your preferred HTTP package

Minimal Setup

Instantiate your API client and a simple repository.

bird looking under
repository_usage.dart
final repository = ItemRepository();

Future<void> fetchItems() async {
  final response = await repository.search(
    filters: [
      Filter(field: 'name', type: 'contains', value: 'Test'),
    ],
  );

  if (response.isSuccessful) {
    print(response.body);
  } else {
    print('Error: ${response.statusCode}');
  }
}
api_client.dart
class ApiHttpClient implements RestApiClient {
  final Dio dio;

  ApiHttpClient({required this.dio});

  @override
  Future<RestApiResponse> get(
    String url, {
    Map<String, String>? headers,
    Map<String, String>? queryParams,
  }) async {
    try {
      final response = await dio.get(
        '\${dio.options.baseUrl}\$url',
        options: Options(headers: headers),
        queryParameters: queryParams,
      );
      return RestApiResponse(
        statusCode: response.statusCode,
        body: response.data,
      );
    } catch (exception, stackTrace) {
      return handleError(exception, stackTrace);
    }
  }

  // post/delete implementations can follow the same pattern
}

Mutations & Actions

Create or update records and trigger custom actions defined in your Laravel backend.

mutations.dart
final newItem = ItemModel(id: 3, name: 'New Item');

await repository.mutate(
  body: LaravelRestApiMutateBody(
    mutate: [
      Mutation(
        operation: MutationOperation.create,
        attributes: newItem.toJson(),
      ),
      Mutation(
        operation: MutationOperation.update,
        key: 3,
        attributes: {'name': 'Updated Name'},
      ),
    ],
  ),
);
actions.dart
await repository.actions(
  data: LaravelRestApiActionsBody(
    fields: [
      Action(name: 'expires_at', value: '2023-04-29'),
    ],
  ),
);
Give Us A Like!

Give Us A Like!

If you enjoyed this project, consider leaving a like on our repository.

Go to the repo