Skip to content

Update REST Style Guide - #1732

Open
andrewnicols wants to merge 10 commits into
moodle:mainfrom
andrewnicols:RestPostOptions
Open

andrewnicols wants to merge 10 commits into
moodle:mainfrom
andrewnicols:RestPostOptions

Conversation

@andrewnicols

Copy link
Copy Markdown
Member

In the creation of the first set of endpoints I encountered a few issues with the REST Style Guide:

  • It should be valid to use a singular naming for something that can only ever be singular (for example, a user's password)
  • Make resource expansion an optional feature
  • error responses:
    • should be RFC-9457 compatible
    • but also define the specific problem, therefore a proposed code + detail has been added
    • and also define errors with specific fields where possible
  • it can be valid to return a null value in certain cases, including:
    • where the field exists but the current access does not grant it
  • endpoints which do not require a scope should explicitly declare it
  • Whilst relative mutation (such as move: 'up') should be banned, some processing control mutations should be allowed - these are things which are instructions for the server to modify the record in a way that cannot be otherwise calculated, for example:
    • generatePassword
    • sendPasswordEmail

andrewnicols and others added 10 commits October 22, 2026 23:13
Allow documented processing controls and permission-limited creation representations. Distinguish administrative credential workflows from privacy-preserving public recovery requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Generalise public access guidance to templates, language strings and recovery. Require the unscoped_resource PHP attribute and distinguish scope exemptions from authentication and capability checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AE-215 user representations return null for hidden email/profile fields and unavailable last-access timestamps. Declare these nullable in OpenAPI without exposing why a value is unavailable or confusing a readable empty string with null.

Keep request nullability independent: a nullable user response must not imply that PATCH accepts null to clear that field.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
In AE-215 an invalid email, unknown PATCH field or incompatible password-generation option is well-formed input that fails validation, not malformed JSON. Require 422 for these cases and reserve 400 for requests that cannot be interpreted, consistently across router and handler validation.

Keep duplicate usernames at 409, authentication-plugin field locks at 403, and stale ETags at 412 so clients can distinguish corrective actions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AE-215 user and custom-field updates need actionable errors for fields such as profile.country and customFields.fields.studentcode. Define details entries containing field, code and message rather than the guide's conflicting nested error envelope.

Stable lowercase codes support integrations while translated messages support forms. Collect independent failures where practical without promising exhaustive validation, and never echo passwords or reset tokens.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AE-215 exposes one profile and one managed password beneath each user. Requiring /profiles or /passwords would imply collections that do not exist, so allow singular nouns for genuine singleton subresources.

Retain plural nouns for users, custom-fields and password-resets collections, together with the existing noun-only and kebab-case conventions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ibility

AE-215 creation clients need to recognise usernameexists rather than parse translated conflict messages. Require a top-level code for documented application-specific problems while allowing generic HTTP/framework failures to use status and RFC 9457 type alone.

Preserve the meaning of deprecated numeric errorcode members until normal removal. Do not overload problem-type URIs or expose account-existence outcomes through public recovery codes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AE-215 already exposes user profile and custom-field resources independently. Mandatory expansion on every single-resource GET would add a response shape and authorisation contract without an established use case.

Allow expansion where useful, requiring documented syntax, relationships, shape, permission filtering and cost/depth limits. Do not choose a global expansion envelope or require new expansion work on the user endpoints.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The AE-215 reset flows need submission and an immediate outcome, not a history of separately addressable reset records. Use singular password-reset paths consistently with singleton naming, removing the invented result GET, identifiers and retention requirement.

Distinguish processing POST responses from creation: return 200 for a synchronous outcome, 204 without a body or 202 for accepted processing. Preserve 201 and Location for workflows that really create addressable resources. Public recovery retains its generic 202 and privacy protections.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:00
@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for moodledevdocs ready!

Name Link
🔨 Latest commit 31de784
🔍 Latest deploy log https://app.netlify.com/projects/moodledevdocs/deploys/6adec24becf47684607ead53
😎 Deploy Preview https://deploy-preview-1732--moodledevdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues were identified across the three changed files, and neither documentation page requires versioned backports.

No open issues 🎉

What changed in this PR

This PR refines Moodle’s REST API style guide to support practical endpoint requirements while retaining consistent resource naming, error handling, and access controls.

Changes:

  • Clarifies singleton resources, optional expansion, nullable responses, and RFC 9457-compatible errors.
  • Defines mutation processing controls, workflow resources, public account recovery, and explicit unscoped declarations.
  • Updates development browser targets and corrects the React theming warning’s admonition type.
File Description
package.json Broadens development browser targets to match production.
docs/​guides/​rest/​style.md Refines REST endpoint contracts and security requirements.
docs/​guides/​javascript/​react/​theming.md Changes the circular-dependency warning to a danger admonition.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants