Skip to content

Conversation

oguzkocer
Copy link
Contributor

@oguzkocer oguzkocer commented Jul 8, 2024

This PR adds support for defining an endpoint namespace for #[derive(WpDerivedRequest)]:

#[derive(WpDerivedRequest)]
#[Namespace("/wp/v2")]
#[SparseField(SparseUserField)]
enum UsersRequest {
    #[contextual_get(url = "/users", params = &UserListParams, output = Vec<SparseUser>)]
    List,
}

Up until this PR, we were using /wp/v2 for all endpoints, hardcoded into the WP_JSON_PATH_SEGMENTS constant. However, the WordPress REST endpoints have different routes, for example Wp Site Health Tests are accessed through /wp-site-health/v1/.

The new Namespace outer attribute takes a single literal token, splits it by / character and extends the base url by appending its parts. This should allow us to describe any route we need.

To Test

  • make test-server && make dump-mysql && make backup-wp-content-plugins
  • cargo test

Note that this PR is assigned to 0.1 milestone, but not because it needs to be included in 0.1, but rather because 0.1 is not cut yet. If the release ends up being cut before merging this PR, we can update it to 0.2.

@oguzkocer oguzkocer added the Rust label Jul 8, 2024
@oguzkocer oguzkocer added this to the 0.1 milestone Jul 8, 2024
@oguzkocer oguzkocer requested a review from jkmassel July 8, 2024 17:09
@oguzkocer oguzkocer enabled auto-merge (squash) July 8, 2024 17:10
@oguzkocer oguzkocer modified the milestones: 0.1, 0.2 Jul 9, 2024
@oguzkocer oguzkocer merged commit 1a742c1 into trunk Jul 9, 2024
@oguzkocer oguzkocer deleted the refactor-api-base-url branch July 9, 2024 19:40
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