Skip to content

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

Closed

Description

@mjfara

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?

Activity

  1. arty1901 commented on Mar 6, 2021

    @arty1901

    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}")]

  2. mjfara commented on Mar 6, 2021

    @mjfara
    Author

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

  3. clairernovotny commented on Mar 19, 2021

    @clairernovotny
    Member

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

  4. mjfara commented on Mar 19, 2021

    @mjfara
    Author

    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

  5. clairernovotny commented on Mar 19, 2021

    @clairernovotny
    Member

    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.

  6. mjfara commented on Mar 19, 2021

    @mjfara
    Author

    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
  7. clairernovotny commented on Mar 27, 2021

    @clairernovotny
    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.

  8. mjfara commented on Mar 27, 2021

    @mjfara
    Author

    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.

  9. Xavier1708 commented on Nov 22, 2022

    @Xavier1708

    Interessante

  10. github-actions commented on Apr 13, 2023

    @github-actions

    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.

  11. locked as resolved and limited conversation to collaborators on Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions