Skip to content

Conversation

oguzkocer
Copy link
Contributor

@oguzkocer oguzkocer commented May 24, 2024

Adds WpEndpointUrl to be used instead of String for the url field of WPNetworkRequest. Adds ApiEndpointUrl to be used internally.

  • WpEndpointUrl is a new type instead of a proper struct. 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 take WpEndpointUrl as a parameter and don't use it anywhere internally - that's what ApiEndpointUrl 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 around Url and allows further processing. I'd have really like to use this type inside WPNetworkRequest 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 to Url 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.

@oguzkocer oguzkocer changed the title WpEndpointUrl WpEndpointUrl & ApiEndpointUrl May 24, 2024
@oguzkocer oguzkocer added the Rust label May 24, 2024
@oguzkocer oguzkocer added this to the 0.1 milestone May 24, 2024
@oguzkocer oguzkocer marked this pull request as ready for review May 24, 2024 00:44
@oguzkocer oguzkocer requested review from crazytonyli and jkmassel May 24, 2024 00:44
}
}

// TODO: Remove this because we want to build all requests within the crate
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@oguzkocer oguzkocer merged commit 77f070e into trunk May 24, 2024
@oguzkocer oguzkocer deleted the api-endpoint-url branch May 24, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants