| name | wp-api-endpoints |
| description | Guide for adding new WordPress REST API endpoints and types to the wordpress-rs codebase. Use when (1) adding new sparse types or context-aware API response types, (2) implementing new REST API endpoint request builders, (3) adding error handling and integration tests for endpoints, or (4) creating ID wrapper types or parameter types for API operations. |
Adding WordPress REST API Endpoints
This codebase uses procedural macros to handle WordPress's context-aware responses (view, edit, embed) and maintain type safety.
1. Adding New Types
Create types in wp_api/src/{endpoint_name}.rs.
Sparse Types
#[derive(Debug, Serialize, Deserialize, uniffi::Record, WpContextual)]
pub struct SparseUser {
#[WpContext(edit, embed, view)]
pub id: Option<UserId>,
#[WpContext(edit)]
pub username: Option<String>,
}
- Prefix type name with
Sparse, all fields Option<T>
#[WpContext(...)] per API docs; #[WpContextualOption] keeps fields optional in generated types
- Omit
_links and _meta fields (add a comment for _meta)
ID Wrapper Types
impl_as_query_value_for_new_type!(UserId);
uniffi::custom_newtype!(UserId, );
( );