Skip to content

New REST API Endpoints for the block editor#95

Open
s3rgiosan wants to merge 127 commits intofeature/helpersfrom
feature/rest-api-endpoint
Open

New REST API Endpoints for the block editor#95
s3rgiosan wants to merge 127 commits intofeature/helpersfrom
feature/rest-api-endpoint

Conversation

@s3rgiosan
Copy link
Copy Markdown
Member

@s3rgiosan s3rgiosan commented Feb 18, 2025

Warning

This PR is based on top of #96

Description of the Change

This PR adds REST API endpoints for searching, retrieving, and managing post relationships, improving integration with the Block Editor and other WordPress components. The implementation leverages the helper functions introduced in #96 to provide a clean, modular API.

V1 Endpoints:

  • POST /content-connect/v1/search - Search for posts and users with nonce-based authentication, supporting pagination and filtering by post type or relationship.

V2 Endpoints:

  • GET /content-connect/v2/relationships - Retrieves all relationships by type, with optional filtering by key, post type, or from/to post types.
  • GET /content-connect/v2/post/{post_id}/relationships - Retrieve all relationships associated with a post, with support for filtering by relationship type, post type, and context (view/embed).
  • GET /content-connect/v2/post/{post_id}/related - Retrieve entities related to a post for a specific relationship, with pagination, ordering, and filtering support.
  • POST /content-connect/v2/post/{post_id}/related - Update the complete list of related entities for a post, preserving sort order for sortable relationships.
  • PUT /content-connect/v2/post/{post_id}/related - Add a single related entity to a post.
  • DELETE /content-connect/v2/post/{post_id}/related - Remove a related entity from a post.

REST API Link Integration:

  • Automatically adds content-connect:relationships and content-connect:related links to REST API responses for all post types that support REST, enabling discoverability of relationship endpoints.

All endpoints include proper permission checks, input validation, error handling, and integration tests covering authentication, pagination, filtering, ordering, and edge cases.

Closes #78

How to test the Change

  1. V1 Search Endpoint:

    • Make a POST request to /content-connect/v1/search with a valid nonce and search query
    • Test searching for posts and users separately
    • Verify pagination works correctly
  2. V2 Relationships Endpoint:

    • GET /content-connect/v2/relationships to list all relationships
    • Test filtering by rel_type, filter_by, and filter_value parameters
  3. V2 Post Relationships Endpoint:

    • GET /content-connect/v2/post/{post_id}/relationships to retrieve relationships for a specific post
    • Test filtering by rel_type, post_type, and context parameters
    • Verify context=embed includes related entities in the response
  4. V2 Post Related Entities Endpoint:

    • GET /content-connect/v2/post/{post_id}/related?rel_key={key}&rel_type={type} to retrieve related entities
    • Test pagination, ordering, and filtering
    • POST to update the complete list of related entities
    • PUT to add a single related entity
    • DELETE to remove a related entity
  5. REST API Links:

    • Retrieve any post via the WordPress REST API (e.g., /wp/v2/posts/{id})
    • Verify that _links includes content-connect:relationships and content-connect:related links when the post has relationships

Changelog Entry

Added - POST /content-connect/v1/search - Search endpoint for posts and users with nonce-based authentication and pagination support.
Added - GET /content-connect/v2/relationships - Retrieves all relationships by type with optional filtering.
Added - GET /content-connect/v2/post/{post_id}/relationships - Retrieve all relationships associated with a post with filtering and context support.
Added - GET /content-connect/v2/post/{post_id}/related - Retrieve entities related to a post with pagination, ordering, and filtering support.
Added - POST /content-connect/v2/post/{post_id}/related - Update the complete list of related entities for a post.
Added - PUT /content-connect/v2/post/{post_id}/related - Add a related entity to a post.
Added - DELETE /content-connect/v2/post/{post_id}/related - Remove a related entity from a post.
Added - Automatic REST API link integration for post types that support REST, adding content-connect:relationships and content-connect:related links to post responses.
Added - Integration tests for all REST API endpoints covering authentication, permissions, pagination, filtering, ordering, and error cases.

Credits

Props @s3rgiosan

Checklist:

dependabot Bot and others added 30 commits March 1, 2023 18:02
Bumps [minimist](https://github.com/minimistjs/minimist), [minimist](https://github.com/minimistjs/minimist) and [mkdirp](https://github.com/isaacs/node-mkdirp). These dependencies needed to be updated together.

Updates `minimist` from 1.2.0 to 1.2.8
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](minimistjs/minimist@v1.2.0...v1.2.8)

Updates `minimist` from 1.2.5 to 1.2.8
- [Release notes](https://github.com/minimistjs/minimist/releases)
- [Changelog](https://github.com/minimistjs/minimist/blob/main/CHANGELOG.md)
- [Commits](minimistjs/minimist@v1.2.0...v1.2.8)

Updates `mkdirp` from 0.5.1 to 0.5.6
- [Release notes](https://github.com/isaacs/node-mkdirp/releases)
- [Changelog](https://github.com/isaacs/node-mkdirp/blob/main/CHANGELOG.md)
- [Commits](isaacs/node-mkdirp@0.5.1...v0.5.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: minimist
  dependency-type: indirect
- dependency-name: mkdirp
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps the npm_and_yarn group with 10 updates:

| Package | From | To |
| --- | --- | --- |
| [braces](https://github.com/micromatch/braces) | `2.3.2` | `3.0.3` |
| [watchify](https://github.com/browserify/watchify) | `3.11.1` | `4.0.0` |
| [browserify-sign](https://github.com/crypto-browserify/browserify-sign) | `4.0.4` | `4.2.3` |
| [elliptic](https://github.com/indutny/elliptic) | `6.5.4` | `6.6.1` |
| [fsevents](https://github.com/fsevents/fsevents) | `1.2.7` | `2.3.3` |
| [got](https://github.com/sindresorhus/got) | `7.1.0` | `11.8.6` |
| [vue-resource](https://github.com/pagekit/vue-resource) | `1.3.4` | `1.5.3` |
| [shell-quote](https://github.com/ljharb/shell-quote) | `1.6.1` | `1.8.2` |
| [tough-cookie](https://github.com/salesforce/tough-cookie) | `2.5.0` | `removed` |
| [node-sass](https://github.com/sass/node-sass) | `7.0.0` | `9.0.0` |


Updates `braces` from 2.3.2 to 3.0.3
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/commits/3.0.3)

Updates `watchify` from 3.11.1 to 4.0.0
- [Release notes](https://github.com/browserify/watchify/releases)
- [Changelog](https://github.com/browserify/watchify/blob/master/CHANGELOG.md)
- [Commits](browserify/watchify@v3.11.1...v4.0.0)

Updates `browserify-sign` from 4.0.4 to 4.2.3
- [Changelog](https://github.com/browserify/browserify-sign/blob/main/CHANGELOG.md)
- [Commits](browserify/browserify-sign@v4.0.4...v4.2.3)

Updates `elliptic` from 6.5.4 to 6.6.1
- [Commits](indutny/elliptic@v6.5.4...v6.6.1)

Updates `fsevents` from 1.2.7 to 2.3.3
- [Release notes](https://github.com/fsevents/fsevents/releases)
- [Commits](fsevents/fsevents@v1.2.7...v2.3.3)

Updates `got` from 7.1.0 to 11.8.6
- [Release notes](https://github.com/sindresorhus/got/releases)
- [Commits](sindresorhus/got@v7.1.0...v11.8.6)

Updates `vue-resource` from 1.3.4 to 1.5.3
- [Release notes](https://github.com/pagekit/vue-resource/releases)
- [Commits](pagekit/vue-resource@1.3.4...1.5.3)

Updates `shell-quote` from 1.6.1 to 1.8.2
- [Changelog](https://github.com/ljharb/shell-quote/blob/main/CHANGELOG.md)
- [Commits](ljharb/shell-quote@v1.6.1...v1.8.2)

Removes `tough-cookie`

Updates `node-sass` from 7.0.0 to 9.0.0
- [Release notes](https://github.com/sass/node-sass/releases)
- [Changelog](https://github.com/sass/node-sass/blob/master/CHANGELOG.md)
- [Commits](sass/node-sass@v7.0.0...v9.0.0)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: watchify
  dependency-type: direct:development
  dependency-group: npm_and_yarn
- dependency-name: browserify-sign
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: elliptic
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: fsevents
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: got
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: vue-resource
  dependency-type: direct:development
  dependency-group: npm_and_yarn
- dependency-name: shell-quote
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: tough-cookie
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: node-sass
  dependency-type: direct:development
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
# Conflicts:
#	package-lock.json
# Conflicts:
#	package-lock.json
#	package.json
# Conflicts:
#	includes/Registry.php
# Conflicts:
#	content-connect.php
#	includes/API/Search.php
#	includes/Plugin.php
@s3rgiosan
Copy link
Copy Markdown
Member Author

@rickalee PR is ready for review. The 1.7.0-beta.1 tag on release/1.7.0 should help with testing in your projects. Let me know if you find any issues.

cc @jeffpaul @fabiankaegy

@s3rgiosan s3rgiosan mentioned this pull request Jan 12, 2026
4 tasks
@s3rgiosan s3rgiosan requested a review from jeffpaul as a code owner January 12, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Code Review

Development

Successfully merging this pull request may close these issues.

Expose functionality through WP REST API

3 participants