Last updated:
0 purchases
sim api
SimApi #
SimApi is a powerful and flexible library for simulating API responses in Dart. It allows developers to create mock APIs for testing and development purposes without the need for a real backend server.
Features #
Simulate HTTP methods: GET, POST, PUT, PATCH, DELETE
Customizable response delay to mimic network latency
Support for route parameters and query parameters
Custom route handlers for complex scenarios
Easy data seeding and management
Flexible route registration
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
sim_api: ^0.0.5
copied to clipboard
Then run:
flutter pub get
copied to clipboard
Usage #
Basic Setup #
import 'package:sim_api/sim_api.dart';
void main() {
final api = SimApi<int>();
// Register routes
api.registerRoute('/users');
api.registerRoute('/users', method: SimApiHttpMethod.get, haveRouteParameters: true);
// Seed some data
api.seedData('/users', {
1: {'id': 1, 'name': 'Alice'},
2: {'id': 2, 'name': 'Bob'},
});
// Use the API
api.get(Uri.parse('/users/$1')).then((response) {
print(response.body);
});
}
copied to clipboard
Custom Route Handlers #
simApi.registerRoute(
'/custom',
method: SimApiHttpMethod.get,
handler: (
url, {
body,
headers,
required delete,
required get,
required patch,
required post,
required put,
}) async {
return SimApiHttpResponse.ok({'message': 'custom route'});
},
);
copied to clipboard
Simulating Network Delay #
// Set a global delay
api.delay = 1000; // 1 second delay
// Or use the constructor
final api = SimApi(defaultDelay: 1000);
copied to clipboard
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.