quick_request 0.0.5 copy "quick_request: ^0.0.5" to clipboard
quick_request: ^0.0.5 copied to clipboard

A Flutter package to simplify HTTP requests (GET, POST, PUT, PATCH, DELETE) with automatic JSON encoding/decoding and efficient response handling using ResponseModel.

Quick Request #

The quick_request Flutter package allows you to make HTTP requests quickly and easily. Using the http package, you can perform API requests in a simple and effective manner.

Features #

  • Easy HTTP requests (GET, POST, PUT, PATCH, DELETE)
  • ResponseModel class for handling responses
  • Automatic encoding and decoding of JSON data

Usage #

GET Request
  Future<ResponseModel> fetchPosts() async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts",
    requestMethod: RequestMethod.GET,
  );
}
POST Request
  Future<ResponseModel> createPost(Map<String, dynamic> data) async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts",
    body: data,
    requestMethod: RequestMethod.POST,
  );
}
PUT Request
  Future<ResponseModel> updatePost(int id, Map<String, dynamic> data) async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts/$id",
    body: data,
    requestMethod: RequestMethod.PUT,
  );
}
DELETE Request
  Future<ResponseModel> deletePost(int id) async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts/$id",
    requestMethod: RequestMethod.DELETE,
  );
}

PATCH Request
  Future<ResponseModel> patchPost(int id, Map<String, dynamic> data) async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts/$id",
    body: data,
    requestMethod: RequestMethod.PATCH,
  );
}
Authorized Request
  Future<ResponseModel> fetchSecurePosts() async {
  String? token = LocalManager().getStringValue(LocalManagerKeys.accessToken);
  return await QuickRequest().request(
    url: "https://api.example.com/secure-posts",
    bearerToken: token,
    requestMethod: RequestMethod.GET,
  );
}
GET Request with Query Parameters
  Future<ResponseModel> fetchPostsWithQueryParameters() async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts",
    queryParameters: {
      "userId": "1",
    },
    requestMethod: RequestMethod.GET,
  );
}

Example PATCH Request
  Future<ResponseModel> patchPostExample(int postId, String newTitle) async {
  return await QuickRequest().request(
    url: "https://api.example.com/posts/$postId",
    body: {"title": newTitle},
    requestMethod: RequestMethod.PATCH,
  );
}

with alert_craft usage
  Future<void> _fetchData() async {
    final apiRequest = QuickRequest();
    try {
      final response = await apiRequest.request(
        url: 'https://api.example.com/posts/1',
        requestMethod: RequestMethod.GET,
      );
      if (!response.error) {
        setState(() {
          
          ShowAlert().showToastMessage(type: 1, title: "successful", description: "response.data");
        });
      } else {
        setState(() {
          ShowAlert().showAlertDialog(type: 1, title: "error", description: "response.message");
        });
      }
    } catch (e) {
      setState(() {
        _responseMessage = 'Exception: $e';
      });
    }
  }

Installation #

To add the quick_request package to your project, include the following line in your pubspec.yaml file:

dependencies:
  quick_request: ^0.0.1
2
likes
130
points
31
downloads

Publisher

verified publisheryeksoftware.com.tr

Weekly Downloads

A Flutter package to simplify HTTP requests (GET, POST, PUT, PATCH, DELETE) with automatic JSON encoding/decoding and efficient response handling using ResponseModel.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on quick_request