Skip to content

Instantly share code, notes, and snippets.

@tcrsavage
Created June 3, 2020 12:51
Show Gist options
  • Save tcrsavage/e909efdb7c58422896d3fa8b686385b4 to your computer and use it in GitHub Desktop.
Save tcrsavage/e909efdb7c58422896d3fa8b686385b4 to your computer and use it in GitHub Desktop.
Dart construct API request URL with default GET params
main() {
Map <String, String> args = {'filter_visibility' : 'false' };
print( getMediaAssetCollectionArgs( args ) );
print( getRequestURi( getMediaAssetCollectionArgs( args ) ) );
}
Map getMediaAssetCollectionArgs( Map args ) {
Map <String, String> defaults = { 'filter_playability' : 'true' };
Map <String, String> combined = {};
combined.addAll( defaults );
combined.addAll( args );
return combined;
}
String getRequestURi( Map<String, String> args ) {
Uri uri = new Uri(
scheme: 'https',
host: 'localhost',
port: 8080,
path: 'myapp',
queryParameters: args
);
return uri.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment