Created
June 3, 2020 12:51
-
-
Save tcrsavage/e909efdb7c58422896d3fa8b686385b4 to your computer and use it in GitHub Desktop.
Dart construct API request URL with default GET params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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