-
Notifications
You must be signed in to change notification settings - Fork 3
WpEndpointUrl
& ApiEndpointUrl
#113
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
Conversation
} | ||
} | ||
|
||
// TODO: Remove this because we want to build all requests within the crate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I agree with this – I'd be happy to have a failable initializer that won't let you make an invalid WPNetworkRequest
, but I'd expect that some app developer will have a need to construct their own and use the underlying library plumbing to execute it?
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are discussing this a bit on Slack. If we decide to remove it, I'll do so as part of another PR.
let mut request = self | ||
.client | ||
.request(Self::request_method(wp_request.method), wp_request.url) | ||
.request(Self::request_method(wp_request.method), wp_request.url.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we implement ToString on WpEndpointUrl
to avoid the need for the .0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToString
doesn't work unfortunately. We'd have to implement IntoUrl which is part of reqwest
and only available as a dev dependency. We'll likely have a cargo feature to add reqwest
at which time we can do this, but until then, I think we can keep this as is.
Adds
WpEndpointUrl
to be used instead ofString
for theurl
field ofWPNetworkRequest
. AddsApiEndpointUrl
to be used internally.WpEndpointUrl
is a new type instead of a properstruct
. I've played with both approaches and I found the new type to be more ergonomic. We are also not trying to guard against anything as we never takeWpEndpointUrl
as a parameter and don't use it anywhere internally - that's whatApiEndpointUrl
is for. So, the main point of this type is to communicate that this is a value that's constructed by us.ApiEndpointUrl
is the internal type that each endpoint implementation will return. This is a wrapper aroundUrl
and allows further processing. I'd have really like to use this type insideWPNetworkRequest
and only expose a function that returns the url as a string, however I can't find a way to do this with uniffi. I've spent quite a bit of time trying to get a structure where Rust consumers will get direct access toUrl
type, but every solution I found made it worse either performance-wise or risky in terms of FFI. We don't really expect Rust clients to further process this value either, so practically speaking, not much value is lost by converting to a string.