sim_api 0.0.1 copy "sim_api: ^0.0.1" to clipboard
sim_api: ^0.0.1 copied to clipboard

This package is particularly useful for Flutter app development but can be integrated into any Dart project where offline API simulation is required. It provides a robust and easy-to-use toolset for e [...]

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.1

Then run:

flutter pub get

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);
  });
}

Custom Route Handlers #

api.registerRoute('/custom', handler: (data, headers) {
  return SimApiHttpResponse.ok({'message': 'Custom response'});
});

Simulating Network Delay #

// Set a global delay
api.delay = 1000; // 1 second delay

// Or use the constructor
final api = SimApi(defaultDelay: 1000);

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.

1
likes
0
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

This package is particularly useful for Flutter app development but can be integrated into any Dart project where offline API simulation is required. It provides a robust and easy-to-use toolset for ensuring that your application handles various API scenarios effectively, without the need for live API endpoints. Whether you're developing new features, testing integrations, or troubleshooting issues, SimApi offers the tools needed to create a realistic and controllable testing environment.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on sim_api