8000 [BUG] URL path must start with '/' and be of the form '/foo/bar/baz' · Issue #1105 · reactiveui/refit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[BUG] URL path must start with '/' and be of the form '/foo/bar/baz' #1105

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

Closed
mjfara opened this issue Mar 5, 2021 · 10 comments
Closed

[BUG] URL path must start with '/' and be of the form '/foo/bar/baz' #1105

mjfara opened this issue Mar 5, 2021 · 10 comments
Labels

Comments

@mjfara
Copy link
mjfara commented Mar 5, 2021

Is this enforced for any reason?
I have a particular case where I do not want to start the url with a '/'

For instance, take this generic Get:

        [Get("({key})")]
        Task<T> Get(TKey key);

My base address is something like:
mysite.com/contacts

And I would like the attribute to simply append an id in brackets (123-456-789), resulting in:
mysite.com/contacts(123-456-789)

Any way to hack around this?

@mjfara mjfara added the bug label Mar 5, 2021
@arty1901
Copy link
arty1901 commented Mar 6, 2021

Are you sure that your way of building url is correct? It doesn't make sense
Thats would be better:
Base address: mysite.com
[Get("contacts/{key}")]

@mjfara
Copy link
Author
mjfara commented Mar 6, 2021

Yup I'm positive. The Microsoft Dynamics Web Api is using OData.

@clairernovotny
Copy link
Member

@arty1901's answer looks correct.... can you please explain why that won't work?

@mjfara
Copy link
Author
mjfara commented Mar 19, 2021

I am trying to make a generic class for this, so I would not want to include "contacts" in the route.
Aside from that, his answer would fail as well because there is no leading slash "/".

I submitted a very simple PR to rectify this:
#1113

@clairernovotny
Copy link
Member
clairernovotny commented Mar 19, 2021

What is the value in having this completely generic?

Like why not have

[Get("/contacts({key})")]
Task<T> GetContacts(Key key);

[Get("/sales({key})")]
Task<T> GetSales(Key key);

Or use two different interfaces, IContacts, and ISales. As you're setting the base address differently for each, you already have different client instances.

The design here looks strange.

@mjfara
Copy link
Author
mjfara commented Mar 19, 2021

I got this design straight from the refit docs:
https://github.com/reactiveui/refit#using-generic-interfaces

The only difference is, I do not want to be forced to include a leading slash "/".

There are ~100 different entities in Dynamics, so rather than writing hundreds of different methods to perform simple CRUD operations, having a generic service for this seems like the better approach.

I am currently using the multiple service approach but feel it's a lot of wasted time and effort when a single generic class can do it all.

My proposed change simply allows bypassing of the arbitrary enforcement of the leading slash.

GitHub
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface. - reactiveui/refit

@clairernovotny
Copy link
Member

@mjfara I would recommend using a custom delegating HttpHandler that can rewrite the URLs that you need. We're not going to be changing this behavior at this time.

@mjfara
Copy link
Author
mjfara commented Mar 27, 2021

Hmm, a custom delegating HttpHandler that removes the forced leading slash is pretty hacky when compared to including an option to override the arbitrary enforcement to begin with.

It wouldn't be a change of behavior, but rather an option in the RefitSettings, the default does not change. Not sure why this isn't being considered seeing as it cleanly resolves this issue.

I do appreciate the workaround, but feels hacky to be doing some string substitution on the url. I guess I'll stick with my forked repo for now.

@Xavier1708
Copy link

Interessante

@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 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
0