Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class GithubService {
private IHttpClientFactory httpClientFactory;
private static string GITHUB_API_URL = "";
public GithubService(IHttpClientFactory clientFactory) {
httpClientFactory = clientFactory;
public async Task<List<GithubRepository>> FetchUserRepositories(string username) {
var repositories = new List<GithubRepository>();
if (!string.IsNullOrEmpty(username)) {
var httpClient = httpClientFactory.CreateClient();
string reposUrl = GetUserReposUrl(username);
var apiResponse = await httpClient.GetAsync(reposUrl);
if (apiResponse.IsSuccessStatusCode) {
string json = await apiResponse.Content.ReadAsStringAsync();
return repositories;
private static string GetUserReposUrl(string username) {
return $"{GITHUB_API_URL}/users/{username}/repos";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.