Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add support for interface default methods #1018

Closed
MariusVolkhart opened this issue Jan 6, 2021 · 2 comments · Fixed by #1031
Closed

feature: Add support for interface default methods #1018

MariusVolkhart opened this issue Jan 6, 2021 · 2 comments · Fixed by #1031

Comments

@MariusVolkhart
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I have a service that exposes an API that isn't very ergonomic. We see callers repeatedly writing the same 5 lines to interact with the service. We'd like to make it easier by adding a default method to our Refit interface that does the logic of those 5 lines, which includes calling a Refit-annotated method.

interface Mine {
  [Get("/events.json")]
  Task<Events> GetEvents(string query);
  
  Task<Events> GetEventsOrDefault(string query) {
    try {
      GetEvents(query);
    } catch (ApiException e) {
        // Look at exception for Reasons
    }
}

Describe the solution you'd like
Right now, Refit errors with the message, "System.NotImplementedException : Either this method has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument."

#845 Had a fix for static default methods, but it does not appear to address default instance methods.

Describe alternatives you've considered
For now we're using an extension method

@MariusVolkhart
Copy link
Contributor Author

🥳 thanks for doing this @clairernovotny!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants