generic_network 1.0.2 copy "generic_network: ^1.0.2" to clipboard
generic_network: ^1.0.2 copied to clipboard

generic network layer with minimal code

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

1
likes
110
points
34
downloads

Publisher

unverified uploader

Weekly Downloads

generic network layer with minimal code

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

dio, flutter

More

Packages that depend on generic_network