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

Shared URL prefix and placeholder values #465

Open
thomaslevesque opened this issue Apr 20, 2018 · 3 comments
Open

Shared URL prefix and placeholder values #465

thomaslevesque opened this issue Apr 20, 2018 · 3 comments

Comments

@thomaslevesque
Copy link

thomaslevesque commented Apr 20, 2018

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.

@tibitoth
Copy link

I think this would be great.

@bennor
Copy link
Contributor

bennor commented Jun 11, 2019

This might be better achieved with the property support described in #163. If/when that's implemented, I think this makes sense.

@JesseKlaasse
Copy link

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 - #1685

I think this would be very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants