Configurable base paths for one API
I am trying to use Refit for an API that has weird routing/paths that are not very RESTful. It has the same base url but each function has its own unique Guid and couple of other things. I want to make these things configurable. Is it doable?
public interface ISomeApi
{
[Get("{some-configurable-value-1}/{id}")]
Task<Something> GetSomething(string id);
[Get("{some-configurable-value-2}/{id}")]
Task<SomethingElse> GetSomethingElse(string id);
}
So far - the only option I've been able to think of is to have one Refit interface per path and set a different base url for each of those interfaces which are configurable.
I'm not sure if this covers it, but you can provide those arguments as parameters:
public interface ISomeApi
{
[Get("{prefix}/{id}")]
Task<Something> GetSomething(string prefix, string id);
[Get("{prefix}/{id}")]
Task<SomethingElse> GetSomethingElse(string prefix, string id);
}
The other option is the one you suggested -- using a different base URL for two different interfaces.
Did you have any other ideas for how an alternative might work?
Also, if your API is really that simple, you could make it generic:
public interface ISomeApi<T>
{
[Get("{prefix}/{id}")]
Task<T> Get(string prefix, string id);
}
Great - the parameter option will work for me! And no, the API isn't as simple to put a generic on it.
Is there an attribute I can use to Uri.UnescapeDataString(path)?
[Get("{path}/{id}")]
Task<Something> GetSomething(string path, string id);
My path value here is of the format /path/to/object/{id}.
Edit: I just checked the underlying implementation and it looks like splitting the value of path into multiple parameters is the only option. Although it'd be great if you can confirm that as I may not have looked hard enough.
Closing because this was a trivial change for me. Also it's more readable anyway since the actual API parameters for me were more along the lines of /{apiName}/{apiVersion}/{apiPath}/{id} and so on.