REST API
questions
FAQ hub aggregating questions from hooks, plugins, jobs, SOLID and WP-CLI sections — for interview prep, code review, and hiring WordPress developers.
Can I add a custom post type’s data to wp/v2 without a custom endpoint?
Yes — registering the post type with show_in_rest => true gives it a full wp/v2-style route automatically, with the same field-extension tools (register_rest_field, meta REST visibility) available on top of it.
Do I need a permission_callback if the route is meant to be public?
Yes, and it should be explicit — __return_true is a valid permission callback that documents the route is intentionally open, rather than an oversight the next developer has to investigate.
Used in
Does showinrest expose a custom field publicly by default?
It depends on how the field was registered — meta fields need an explicit auth_callback if their visibility should be restricted; without one, the default behavior may expose more than intended, so it’s worth checking rather than assuming.
How many routes should share one controller class?
Routes that operate on the same underlying resource — one controller per resource (projects, services, bookings), not one controller for the entire plugin’s API surface.
Used in
How should pagination be enforced on a list endpoint?
With a sensible default per_page and an enforced maximum that a request can’t override, so no single call can pull an unbounded result set regardless of what the client requests.
Is it safe to reuse the wp/v2 namespace for custom routes?
No — wp/v2 belongs to WordPress core, and core can add or change routes under it without warning. Always register custom routes under a namespace unique to the project.
Used in
What does it mean to use the REST API as an aggregation layer?
A single custom endpoint that fetches data from one or more third-party APIs, combines it, and returns one unified response — common on enterprise projects that need to integrate several external systems behind a consistent internal API.
What is REST context and why does it matter for extending wp/v2?
Context (view, edit, embed) controls which fields appear in which situations — a field meant only for the editor’s own use in the edit context shouldn’t also appear in the public view response an anonymous visitor can request.
What is the N+1 query problem in a REST API context?
It’s when a list endpoint runs one additional database query per item in the list to fetch related data, instead of one batched query for the whole list — invisible with ten items, a real bottleneck with a thousand.
What’s the risk of over-extending wp/v2 instead of using a custom route?
The response shape can end up representing something that isn’t really a post, user, or term, forced into a schema that doesn’t naturally fit — at that point a purpose-built custom endpoint documents the data far more clearly.
When should a specialist review custom endpoint design?
Before other consumers depend on the route’s namespace and shape — a WordPress developer experienced with REST API architecture catches versioning and structure problems while they’re still a five-minute fix instead of a breaking migration.
Used in
When should a specialist review REST API performance?
Before a launch expecting meaningful traffic, and always before building an aggregation endpoint combining multiple third-party APIs — the failure and caching strategy is far cheaper to design up front than to retrofit after a production incident.
When should a specialist weigh in on this decision?
Early — before either direction is built out, since undoing an awkward wp/v2 extension or a redundant custom endpoint both cost more than making the right call up front.
When should I use a raw callback instead of extending WPRESTController?
For a single route with one or two methods and no shared validation logic. Once a resource needs multiple methods or the same checks repeated across callbacks, a controller class keeps that logic in one place.
Used in
When should I use registerrestfield instead of a custom endpoint?
When the data is a property of an existing resource — a post, user, or term — rather than a resource in its own right. If it doesn’t need its own create/read/update/delete lifecycle, extending the existing route is almost always simpler.
Why cache REST API responses instead of relying on database query caching alone?
Because computing and formatting the response itself has a cost beyond the database query — caching the finished payload skips all of that work on repeat requests, which matters most for endpoints hit frequently by the same or similar queries.
Why does an aggregation endpoint need independent caching per upstream API?
Because the upstream APIs have different reliability, latency, and rate limits — caching and failing each one independently means a single slow or down integration degrades gracefully instead of taking down the entire response.
Why does my custom route need a version in the namespace?
Because a breaking change to the response shape is inevitable eventually, and a versioned namespace (4wp/v1, 4wp/v2) lets the old and new shapes coexist during a migration instead of forcing every consumer to update at the exact same moment.
Used in
No questions found. Try another search.
Smart FAQ Management
4WP FAQ
Not just another FAQ block. A smart wrapper that adds intelligence
without breaking your design.