refit: Refit doesnt allow constant variable from another class ?

How to define a constant variable for path “index.php?route=mobile” ? I defined in another class a constant variable.

Config.cs

public const  String SERVICE_PATH = "/index.php?route=mobile";

APIService.cs

 [Post(Config.SERVICE_PATH+"/login")]
        Task<string> login([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, string> userInfo);

But refit throws an error like this :

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.

Full part of my service interface :

public interface APIService
{
        [Post("/index.php?route=mobile/login")]
        Task<string> login([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, string> userInfo);

        [Post("/index.php?route=mobile/account/register")]
        Task<string> register([Body(BodySerializationMethod.UrlEncoded)] Dictionary<string, string> userInfo);

        [Get("/index.php?route=mobile/account/forgotPassword&email={email}")]
        Task<string> forgotPassword(String email);
}

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 21 (10 by maintainers)

Most upvoted comments

Please try v6.0-preview.84 and file bugs as you come across them.

Yeah, I know how it works 😂

I was referring to why the change was made from runtime method interception in 2.0. Was originally for iOS but then we added support for WinRT.

@bennor it’s not just for iOS that we do compile-time code gen, it’s also for the WinRT/UWP platforms as well.

@Cheesebaron you are right, as well 😃

it seems like a Refit limitation to handle / after a query parameter. But _http://example.org/index.php?route=mobile/account/register_ is a valid Uri and Url.

as the following link from Gmail to this issue implies.

_https://www.google.com/url?q=https://github.com/paulcbetts/refit/issues/263&source=gmail_

i trimmed out some personal info from the Url but you get the point.

This is a weird one. Shouldn’t the const get inlined at compile time? I’m assuming you get the same error if you redefine the const as a static readonly string? public static readonly String SERVICE_PATH = "/index.php?route=mobile";