Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created January 13, 2018 16:41
Show Gist options
  • Select an option

  • Save sreeprasad/2e7d27b7418a8980ad99b92df83748f7 to your computer and use it in GitHub Desktop.

Select an option

Save sreeprasad/2e7d27b7418a8980ad99b92df83748f7 to your computer and use it in GitHub Desktop.
Shows how to create a URL
final static String GITHUB_BASE_URL =
"https://api.github.com/search/repositories";
final static String PARAM_QUERY = "q";
final static String PARAM_SORT = "sort";
final static String sortBy = "stars";
public static URL buildUrl(String githubSearchQuery) {
Uri uri = Uri.parse(GITHUB_BASE_URL)
.buildUpon()
.appendQueryParameter(PARAM_QUERY,githubSearchQuery)
.appendQueryParameter(PARAM_SORT, sortBy)
.build();
URL queryURL = null;
try {
queryURL = new URL(uri.toString());
}catch (MalformedURLException e) {
e.printStackTrace();
}
return queryURL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment