this package create generic network layer with minimal code
Features
A powerful HTTP networking package for Flutter, that aims to handle http requests with minimal clean code , with ease error handling
Getting started
class Api extends BaseApi{
Api():super(url:"your base url");
}
class LoginRequest extends TargetType{
final String email;
final String password;
LoginRequest({required this.password,required this.email}){
requestParameters = {"password":password,"email":email};
}
@override
String? get path => "end point";
//http method
@override
HttpMethod? get method => HttpMethod.get;
// any extra headers for this
@override
Map<String, dynamic>? headers = {};
@override
var requestParameters;
}
// and here how should our response looks like
class LoginResponse extends Decodable<LoginResponse>{
String? userName;
int? age;
@override
LoginResponse fromJson(json) {
return LoginResponse.fromJson(age: json["age"], userName: json["userName"]);
}
LoginResponse();
LoginResponse.fromJson({required this.age,required this.userName,});
}
// finally we now can call the request
login(){
Api().fetchData<LoginResponse,LoginResponse>(LoginRequest(), LoginResponse()).then((value) {
if (value case Success(value: final value)) {
print(value);
} else if (value case Failure(exception: final value)) {
print(value);
}
});
}
Usage
this package create generic network layer with minimal code
to /example
folder.
const like = 'sample';
Additional information
this package create generic network layer with minimal code handling the exceptions clean code