Shared URL prefix and placeholder values
I have an interface with methods like this:
interface IItemsClient
{
[Get("/api/tenant/{tenantKey}/item/{itemId}")]
Task<FileSystemItem> GetItemAsync(string tenantKey, string itemId, CancellationToken cancellationToken = default);
[Get("/api/tenant/{tenantKey}/item/{parentId}/children")]
Task<CollectionResponse<FileSystemItem>> GetChildrenAsync(string tenantKey, string parentId, CancellationToken cancellationToken = default);
...
}
The tenantKey is passed in ALL methods, and the /api/tenant/{tenantId} prefix is common to all methods.
Is there a way to somehow share the prefix and placeholder value? e.g. doing something like this:
[Prefix("/api/tenant/{tenantKey}/item"]
interface IItemsClient
{
[Get("/{itemId}")]
Task<FileSystemItem> GetItemAsync(string itemId, CancellationToken cancellationToken = default);
[Get("/{parentId}/children")]
Task<CollectionResponse<FileSystemItem>> GetChildrenAsync(string parentId, CancellationToken cancellationToken = default);
...
}
var itemsClient = RestService.For<IItemsClient>(httpClient, refitSettings, new { tenantKey = "foo" });
This way I wouldn't have to pass the tenantKey explicitly to all methods.
(I realize I could just pass an HttpClient with a different BaseAddress, but I split my API into separate interfaces, and I'd rather use the same HttpClient for all of them)
If it's not supported, I'd be willing to submit a PR to add it.
I think this would be great.
This might be better achieved with the property support described in #163. If/when that's implemented, I think this makes sense.
Since the 'property support' has not been implemented yet and this is such an old post, I have implemented a PR to add this functionality - https://github.com/reactiveui/refit/pull/1685
I think this would be very helpful.