How can I DRY this code?

This page summarizes the projects mentioned and recommended in the original post on /r/dartlang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • api_utils

    Discontinued A collection of helper functions and an ApiResponse class that make working with REST apis a bit easier.

  • This library just ended up doing the same thing that I've done. There's code duplication in get and post functions, for example. They both call _makeRequest and then _handleResult and have wrapped the whole operation in try catch. I just have an added layer of having multiple clients and to keep trying until I get a good response or I run out of tries. What I want to achieve is to extract the common code of get and post to another function so there would be no duplication.

  • typesense-dart

    Dart client for Typesense

  • The node.client is a http client. Both the get and delete functions are identical except for the fact that they invoke different functions of the client. Can I somehow create a private function that contains all the common functionality but also accepts, in addition to other parameters, a function of the client that is to be used? If there exists a way to share the repeating code of all the methods here that would be amazing.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • qiscus-chat-sdk-flutter

    Qiscus provide everything you need to power up your app with chats. And it's now made simple.

  • This is the abstract class: https://github.com/qiscus/qiscus-chat-sdk-flutter/blob/master/lib/src/core/api_request.dart#L5 This is an implementation of that class: https://github.com/qiscus/qiscus-chat-sdk-flutter/blob/master/lib/src/user/user_api_request.dart#L3

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts