Skip to content

Remove url::Url types from public API #513

Description

@DanGould

Our dependency is twofold, in function arguments and in errors. We can more easily maintain stability of our public API if we internalize our url dependencies in both function arguments and in error variants.

Using url::Url in the public API may be a form of tech debt, in that we took it on to get the API out without full consideration at the time the dep was first introduced by Kixunil.

Don't' depend on url::Url in function arguments

Instead, take Url arguments as IntoUrl trait implementations in core typestate machine instead of url::Url.

We have to re-export url::Url, bind to it, and have downstream implementers manually parse URLs before payjoin will accept them as arguments to many functions that produce requests e.g. Sender::extract_v2.

Instead, an IntoUrl trait like reqwest over &'a str, &'a String, String that handles Url validation inside the typestate machine would abstract this burden from an end user and make one less error for them to handle since it'd be encapsulated in our variants resulting from those extract or setup functions.

related: #459

Don't depend on url in public error variants.

We have no explicit url::ParseError variants in our Error types because they're only internal variants, but if we were to make those variants public we would. We also make downstream users construct their own Urls to pass to our functions which makes them handle the ParseError on their own rather than encapsulating that logic and error handling in our extract_ functions or similar.

related: #403

Activity

  1. added this to the payjoin-1.0 milestone on Jan 27, 2025
  2. nothingmuch commented on Jan 28, 2025

    @nothingmuch
    Contributor

    reqwest's IntoUrl is sealed, but what you're thinking of wouldn't be, right?

  3. DanGould commented on Jan 28, 2025

    @DanGould
    MemberAuthor

    It would be sealed and we'd implement it for &'a str, &'a String and String just like reqwest.

  4. DanGould commented on Jan 30, 2025

    @DanGould
    MemberAuthor

    I realize now that reqwest also re-exports url::Url, which is nice for convenience. There are circumstances where you want to parse URLs early, as in payjoin-cli configuration, and having the preferred type available alongside IntoUrl, with IntoUrl trait implementations on &Url and Url even more ergonomic.

  5. DanGould commented on Mar 20, 2025

    @DanGould
    MemberAuthor

    This is somewhat covered by #520, we're not going to remove url::Url (immediately), but we are using IntoUrl to make the signatures more ergonomic. Whether we want to depend on the url::ParseUrl variants in the public API is a question I haven't answered yet, but am leaning to NOT. Better if we encapsulate it in our own so that downstream won't get a break from the dependency being upgraded.

  6. arminsabouri commented on Sep 8, 2025

    @arminsabouri
    Contributor

    From @DanGould "If we get rid of this [impl IntoUrl for [url::]Url], then we can use string types everywhere"
    https://docs.rs/payjoin/latest/payjoin/trait.IntoUrl.html#implementors

  7. 6 remaining items

  8. DanGould commented on Oct 3, 2025

    @DanGould
    MemberAuthor

    Noted un-completed by #1141

  9. DanGould commented on Oct 3, 2025

    @DanGould
    MemberAuthor

    closed by #1141

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

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions