我试图弄清楚如何使用 Refit 库来发出 GET 请求,但我不知道它为什么不起作用。我正在关注改装 github 页面上的示例。我错过了什么?似乎 GetUser("octocat") 方法不起作用。我尝试搜索有关如何使用 refit 的其他示例,但找不到任何东西。
private static async void getUser()
{
var gitHubApi = RestService.For<IGitHubApi>("https://api.github.com");
var octocat = await gitHubApi.GetUser("octocat");
}
public class User
{
[JsonProperty("login")]
public string Login { get; set; }
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("avatar_url")]
public string AvatarUrl { get; set; }
[JsonProperty("gravatar_id")]
public string GravatarId { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("html_url")]
public string HtmlUrl { get; set; }
[JsonProperty("followers_url")]
public string FollowersUrl { get; set; }
[JsonProperty("following_url")]
public string FollowingUrl { get; set; }
[JsonProperty("gists_url")]
public string GistsUrl { get; set; }
[JsonProperty("starred_url")]
public string StarredUrl { get; set; }
[JsonProperty("subscriptions_url")]
public string SubscriptionsUrl { get; set; }
[JsonProperty("organizations_url")]
public string OrganizationsUrl { get; set; }
[JsonProperty("repos_url")]
public string ReposUrl { get; set; }
[JsonProperty("events_url")]
public string EventsUrl { get; set; }
[JsonProperty("received_events_url")]
public string ReceivedEventsUrl { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("site_admin")]
public bool SiteAdmin { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("company")]
public string Company { get; set; }
[JsonProperty("blog")]
public string Blog { get; set; }
[JsonProperty("location")]
public string Location { get; set; }
[JsonProperty("email")]
public object Email { get; set; }
[JsonProperty("hireable")]
public object Hireable { get; set; }
[JsonProperty("bio")]
public object Bio { get; set; }
[JsonProperty("public_repos")]
public long PublicRepos { get; set; }
[JsonProperty("public_gists")]
public long PublicGists { get; set; }
[JsonProperty("followers")]
public long Followers { get; set; }
[JsonProperty("following")]
public long Following { get; set; }
[JsonProperty("created_at")]
public System.DateTimeOffset CreatedAt { get; set; }
[JsonProperty("updated_at")]
public System.DateTimeOffset UpdatedAt { get; set; }
}
interface IGitHubApi
{
[Get("/users/{user}")]
Task<User> GetUser(string user);
}