-
Notifications
You must be signed in to change notification settings - Fork 3
Introduces RequestBuilder
#114
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
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.
Makes sense so far – one thing I wanted to leave in a public channel though for future reference.
Why these abstractions vs just having a very log lib.rs
with 1000 repeated versions of this?
WPNetworkRequest {
method: RequestMethod::POST,
url: self.api_endpoint.users.create().into(),
header_map: self.header_map_for_post_request(),
body: serde_json::to_vec(¶ms).ok(),
}
api_endpoint: ApiEndpoint, | ||
authentication: WPAuthentication, | ||
request_builder: Arc<RequestBuilder>, | ||
users_request: UsersRequestBuilder, |
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.
users_request
is a bit of an awkward name, but I'm assume it's to make things nice for a caller like:
helper.users_request.create()
If not, we might want to consider just calling it users_request_builder
, as lengthy as that is? 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.
I forgot to add the _builder
suffix after fe13c62. I'll do that in the next iteration of WPApiHelper
.
let url = Url::parse(site_url.as_str()).unwrap(); | ||
// TODO: Handle the url parse error | ||
let api_endpoint = ApiEndpoint::new_from_str(site_url.as_str()).unwrap(); | ||
let api_base_url = Arc::new(ApiBaseUrl::new(site_url.as_str()).unwrap()); |
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.
I'm not sure about using Arc<T>
for all of these vs just using .clone()
(which is IMHO simpler because we pay all the costs upfront), but given the fact that all our FFI already uses Arc<T>
, we can defer this and adjust if needed – callers shouldn't be affected.
This is a bit difficult to handle at the moment, as I don't know what our final design will look like. I think The |
This PR is a step in organizing
WPApiHelper
. It introduces aRequestBuilder
type that takes anAuthentication
and provides helpers forget
,post
&delete
requests. Using thisRequestBuilder
,UsersRequestBuilder
&PluginsRequestBuilder
encapsulates the logic that was handled byWPApiHelper
.It removes the
ApiEndpoint
type as we no longer need an encapsulating type for all endpoints. Each request builder will only work with its own endpoint implementation. Furthermore, theapi_base_url
field for these endpoints have been changed to anArc<ApiBaseUrl>
so that we can have a single instance of it and not have to clone the whole thing everywhere.Public API for
WPApiHelper
was not altered for this PR so that it's not a breaking change for our clients. I'd like to do the breaking changes in its own PR to make it easier to follow the changes.To Test
make test-server && make dump-mysql && make backup-wp-content-plugins
cargo test --test '*' -- --nocapture --test-threads 1