Menu

1 / 5

dio_essentials: four Dio interceptors for dedup, retry, token refresh and logging

DEV Community: mobile·Abdeldjalil Chougui·2 days ago
#eQBnOHpT
#devtomobile#devto#dev#refresh#token
Reading 0:00
15s threshold

Many apps that use Dio end up with the same four interceptors. One retries failed requests. One attaches the access token and refreshes it on a 401 . One logs. And at some point someone adds a fourth to stop the same GET from firing three times when three widgets build together.

They are usually written by hand, in a hurry, and they tend to have the same bugs. The retry delay is linear and zero on the first retry. The retry replays a POST , and the server may run the same write twice. Five requests get a 401 at once and the app refreshes the token five times. The logger prints the Authorization header to the console.

dio_essentials is a pure Dart package with those four interceptors, written to avoid those bugs. Its only dependency is dio , and it works on the VM, Flutter and the web.

What it does

DedupInterceptor

It merges identical in-flight requests into one network call.…

Continue reading — create a free account

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