api_service_interceptor 0.0.3 copy "api_service_interceptor: ^0.0.3" to clipboard
api_service_interceptor: ^0.0.3 copied to clipboard

A Flutter package for API request with Api Service interceptor

api_service_interceptor #

A Flutter package that will help for fetching and passing data to the server.

API Service Interceptor #

pub package

How It Works #

ezgif com-animated-gif-maker

Installation #

Add dependency for package on your pubspec.yaml:

    dependencies:
      api_service_interceptor: latest

or

flutter pub add api_service_interceptor

Features #

ApiServiceInterceptor class has two types of method

  • requestToServer()
  • multipartRequestToServer()

First I describe the "requestToServer()" method. This method takes 4 parameters ->

Parameters Definitions
String requestUrl (Required) [requestUrl] need to pass your API's url.
String requestMethod (Required) [requestMethod] need to pass API's method so that server can understand for which type of request you want.
Object? bodyParams (Optional) [bodyParams] sets the body of the request. It can be a [String], a [List] or a [Map<String, String>]
Map<String, String>? headers (Optional) [headers] need to pass headers because it helps you contain more information about the resource to be fetched, or about the client requesting the resource and also hold additional information about the response, like its location or about the server providing it.

Usage #


final ApiServiceInterceptor apiServiceInterceptor;

Future<ApiResponseModel> loginUser(
      {required String email, required String password}) async {

    String url = "-------- use your api url ---------";

    Map<String, String> bodyParams = {
      "email": email,
      "password": password
    };

    Map<String, String> headers = {'Content-Type': 'application/json'};

    ApiResponseModel responseModel = await apiServiceInterceptor.requestToServer(
        requestUrl: url,
        requestMethod: ApiRequestMethod.postMethod,
        bodyParams: jsonEncode(bodyParams),
        headers: headers
    );

    return responseModel;
}

Additional Information #

This package is built on "http", "http_parser" and "shared_preferences". When we use "api_service_interceptor" package than we also use "shared_preferences" package.

12
likes
150
points
103
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for API request with Api Service interceptor

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, http_parser, shared_preferences

More

Packages that depend on api_service_interceptor