API client for Flutter to communicate with the web-api
GNU General Public License v3.0
6
stars
0
forks
source link
As a developer I would like to have http responses returned from methods in the api client in order to be able to react differently depending on the response code. #89
Currently the api client returns differing types of data. It can eg. be a boolean for logging in.
The official Flutter approach to fetching data from the internet, seen here, is to use the built in http package.
I would like to see the official Flutter approach implemented as this enables the possibility of reacting to the different error codes given back from the web api. This removes the need to throw exceptions when making api calls, due to having the error codes available at the point where the api call is made. The implementation of this issue will also require removing the http class in the api client. This is to avoid conflicts when implementing functionality in the api client.
Another aspect of this refactor is altering the methods in the Http class to return Future<Response> instead of Stream<Response>, as these streams often arent disposed of properly and are only used for singular pieces of data. This also fits into the Flutter approach as the Future<T> class enables await of methods.
Currently the api client returns differing types of data. It can eg. be a boolean for logging in. The official Flutter approach to fetching data from the internet, seen here, is to use the built in
http
package.I would like to see the official Flutter approach implemented as this enables the possibility of reacting to the different error codes given back from the web api. This removes the need to throw exceptions when making api calls, due to having the error codes available at the point where the api call is made. The implementation of this issue will also require removing the http class in the api client. This is to avoid conflicts when implementing functionality in the api client.
An example of the refactor is the login method:
That is the method as of writing this issue. Next is the new version:
Another aspect of this refactor is altering the methods in the Http class to return
Future<Response>
instead ofStream<Response>
, as these streams often arent disposed of properly and are only used for singular pieces of data. This also fits into the Flutter approach as theFuture<T>
class enablesawait
of methods.