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

SimApi is particularly valuable for Flutter app development but can be integrated into any Dart project requiring offline API simulation. It offers a robust, easy-to-use toolset for testing various AP [...]

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

SimApi is particularly valuable for Flutter app development but can be integrated into any Dart project requiring offline API simulation. It offers a robust, easy-to-use toolset for testing various API scenarios without live endpoints. This package is ideal for developing new features, testing integrations, or troubleshooting issues by providing a realistic, controllable testing environment.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on sim_api