Skip to content

Rest Api#9

Merged
jasperf merged 7 commits into
mainfrom
rest-api
May 25, 2026
Merged

Rest Api#9
jasperf merged 7 commits into
mainfrom
rest-api

Conversation

@jasperf

@jasperf jasperf commented May 25, 2026

Copy link
Copy Markdown
Contributor

This release introduces a REST API layer for Waygate v0.7.0, exposing two authenticated endpoints for pattern listing and page creation directly over HTTP. The new REST_API class registers routes under the waygate/v1 namespace, enabling programmatic access to pattern data and AI-driven page generation without requiring the WordPress admin UI. Page creation via the REST API is restricted to draft status to prevent unintended publishing, and a rate-limiting mechanism guards the generation endpoint against abuse. The release includes full unit test coverage for both endpoints and updated documentation throughout.

REST API Architecture:

  • Added includes/class-rest-api.php implementing GET /waygate/v1/patterns for retrieving available block patterns and POST /waygate/v1/pages for triggering AI page generation, both protected by WordPress nonce and capability checks.
  • Page creation via the API is locked to post_status: draft, ensuring generated content requires explicit editorial review before publication.
  • A rate limiter on the page creation endpoint restricts concurrent or rapid requests, protecting against runaway AI API consumption.

Testing:

  • Added tests/Unit/RestApiTest.php with unit tests covering endpoint registration, authentication enforcement, draft-status enforcement, rate limiting behavior, and valid page creation responses.
  • Updated tests/bootstrap.php to include the new REST API class in the test autoloading context.

Documentation and Version Housekeeping:

  • README.md updated with a dedicated REST API section covering endpoint signatures, authentication requirements, and the draft-only constraint introduced in v0.7.0.
  • CHANGELOG.md updated with a [0.7.0] entry documenting all new endpoints, security controls, and behavioral restrictions.
  • docs/ROADMAP.md marks both Prompt Templates and REST API as complete, reflecting the current feature state of the plugin.

Files Changed:

jasperf added 7 commits May 25, 2026 14:40
Registers GET /waygate/v1/patterns (requires edit_posts) and
POST /waygate/v1/pages (requires publish_pages) under the waygate/v1
namespace. Both endpoints delegate to existing Pattern_Lab methods;
failed page creation returns a 422 WP_Error.
Adds RestApiTest (14 tests) covering route registration, get_patterns
filtering, and create_page success/error paths. Extends bootstrap.php
with WP_REST_Request/Response/Server stubs and REST helper function stubs.
POST /waygate/v1/pages now always creates drafts; the status parameter
has been removed to prevent accidental publishing via the API.

Adds a per-user transient-based rate limiter (10 req/60 s) in the
permission callback, returning 429 when exceeded. The limit is
filterable via waygate_rate_limit.
@jasperf jasperf merged commit 7707565 into main May 25, 2026
2 checks passed
@jasperf jasperf deleted the rest-api branch May 25, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant