You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dimitar Zabaznoski edited this page Jun 16, 2021
·
2 revisions
In this project we use HTTP client generator for Dart - chopper
Setup
Chopper library is already set, it is used for getting tasks and authentication of users.
Implemented services:
TasksApiService
UserApiService
UserAuthApiService
HttpApiServiceProvider will configure ChopperClient and all services used.
Feel free to change this configuration as you need.
For more information on getting started with chopper and how to use the ChopperService class head to the chopper's getting started guide.
Authenticator
RefreshTokenAuthenticator is already implemented, this feature will detect 401 HTTP response code and will try to refresh the user token if possible. If the token is refreshed successfully it will repeat the already failed API call with the new token and return as if nothing happened, or if it fails to refresh the token exception will be thrown.
With RefreshTokenAuthenticator you can interceptRequest and interceptResponse.
Converters
JsonTypeConverter is custom converter that is used in this project.
Usage
To use the custom JsonTypeConverter you must register converters for all json serializable models.
If you miss to register a type converter you'll get a warning log at runtime:
Log.w('JsonTypeConverter - No converter found for type: $type');
ResponseToTypeConverter is another custom converter that converts chopper's result Response to BodyType.
For more info on this check the open discussion at chopper's GitHub page.
Interceptors
AuthInteceptor - adds authorization header
ErrorInterceptor - will parse errors
HttpLoggerInterceptor - uses Log instead of chopper logger
LanguageInteceptor - adds preferred language header
VersionInterceptor - adds the supported app version header