Menu

1 / 6

mock_api_assets: a fake backend from JSON fixtures for Dart and Flutter

DEV Community: mobile·Abdeldjalil Chougui·about 1 hour ago
#SzXs0jcc
#devtomobile#devto#dev#router#json
Reading 0:00
15s threshold

Front-end work often starts before the backend is ready. The API is still being designed, or it exists but you are on a train, or you have to demo the app and cannot depend on a server. The usual answer is a few hard-coded lists scattered through the code, which then have to be found and removed later.

A fake backend is a cleaner answer: the app keeps making real HTTP calls through its real client, and something answers them from local JSON files. But a good fake has to do more than return a file. Real APIs are slow, they fail, and they remember what you posted. If the fake does none of that, the loading states, the error screens and the "create then list" flows are never exercised.

mock_api_assets is a fake backend made of JSON fixtures. It has route matching, templated fixtures, simulated latency, error injection, a stateful CRUD store, switchable scenarios, and adapters for Dio and package:http .

What it does

A router. MockRouter matches on the method and a path pattern.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.