Title: REST API Changes in WordPress 5.6
Author: Timothy Jacobs
Published: December 8, 2020

---

 [  ](https://profiles.wordpress.org/timothyblynjacobs/) [Timothy Jacobs](https://profiles.wordpress.org/timothyblynjacobs/)
12:48 pm _on_ December 8, 2020     
Tags: [5.6 ( 85 )](https://make.wordpress.org/core/tag/5-6/),
[dev-notes ( 650 )](https://make.wordpress.org/core/tag/dev-notes/), [rest-api ( 111 )](https://make.wordpress.org/core/tag/rest-api/)

# REST API Changes in WordPress 5.6

WordPress 5.6 introduces a number of changes to the REST APIREST API The REST API
is an acronym for the RESTful Application Program Interface (API) that uses HTTP
requests to GET, PUT, POST and DELETE data. It is how the front end of an application(
think “phone app” or “website”) can communicate with the data store (think “database”
or “file system”) [https://developer.wordpress.org/rest-api/](https://developer.wordpress.org/rest-api/),
some of which have been covered in other dev notesdev note Each important change
in WordPress Core is documented in a developers note, (usually called dev note).
Good dev notes generally include a description of the change, the decision that 
led to this change, and a description of how developers are supposed to work with
that change. Dev notes are published on Make/Core blog during the beta phase of 
WordPress release cycle. Publishing dev notes is particularly important when plugin/
theme authors and WordPress developers need to be aware of those changes.In general,
all dev notes are compiled into a Field Guide at the beginning of the release candidate
phase..

> [Application Passwords: Integration Guide](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/)

> [REST API Batch Framework in WordPress 5.6](https://make.wordpress.org/core/2020/11/20/rest-api-batch-framework-in-wordpress-5-6/)

> [Site Health Check changes in 5.6](https://make.wordpress.org/core/2020/11/15/site-health-check-changes-in-5-6/)

> [New action wp_after_insert_post in WordPress 5.6.](https://make.wordpress.org/core/2020/11/20/new-action-wp_after_insert_post-in-wordpress-5-6/)

Below are some other noteworthy changes that deserve a call out.

## Search

The `wp/v2/search` endpoint introduced in WordPress 5.0 provides a unified interface
for searching across multiple content types. WordPress 5.6 adds a terms and post
formats search handler. For example, to search across terms in all taxonomies, make
the following request: `https://example.org/wp-json/wp/v2/search?type=term&search
=my-term`. To search post-formats, use the `post-format` type: `https://example.
org/wp-json/wp/v2/search?type=post-format&search=aside`.

Additionally, the REST API search infrastructure no longer requires that the `id`
for each item is an integer. Strings are now an acceptable `id` type.

See [#51458](https://core.trac.wordpress.org/ticket/51458), [#51459](https://core.trac.wordpress.org/ticket/51459),
[#51131](https://core.trac.wordpress.org/ticket/51131).

## JSONJSON JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. Schema

### `multipleOf` keyword

The `multipleOf` keyword allows for asserting that an `integer` or `number` type
is a multiple of the given number. For example, this schema will only accept even
integers.

    ```notranslate
    {
      "type": "integer",
      "multipleOf": 2
    }
    ```

`multipleOf` also supports decimals. For example, this schema could be used to accept
a percentage with a maximum of 1 decimal point.

    ```notranslate
    {
      "type": "number",
      "minimum": 0,
      "maximum": 100,
      "multipleOf": 0.1
    }
    ```

See [#51022](https://core.trac.wordpress.org/ticket/51022).

### `minProperties` and `maxProperties`

The `minItems` and `maxItems` keywords can be used for the `array` type. The `minProperties`
and `maxProperties` introduces this same functionality for the `object` type. This
is helpful when using `additionalProperties` to have a list of objects with unique
keys.

This schema requires an object that specifies at least 1, and at most 3, colors.

    ```notranslate
    {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "format": "hex-color"
      },
      "minProperties": 1,
      "maxProperties": 3
    }
    ```

    ```notranslate
    {
      "primary": "#52accc",
      "secondary": "#096484"
    }
    ```

See [#51023](https://core.trac.wordpress.org/ticket/51023).

### `patternProperties`

The `patternProperties` keyword is similar to the `additionalProperties` keyword,
but allows for asserting that the property matches a regex pattern. The keyword 
is an object where each property is a regex [pattern](https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#pattern)
and its value is the JSON Schema used to validate properties that match that pattern.

For example, this schema requires that each value is a hex color and the property
must only contain “word” characters.

    ```notranslate
    {
      "type": "object",
      "patternProperties": {
        "^\\w+$": {
          "type": "string",
          "format": "hex-color"
        }
      },
      "additionalProperties": false
    }
    ```

When the REST API validates the `patternProperties` schema, if a property doesn’t
match any of the patterns, the property will be allowed and not have any validation
applied to its contents. This behaves the same as the `properties` keyword. If this
logic isn’t desired, add `additionalProperties` to the schema to disallow non-matching
properties. See [#51024](https://core.trac.wordpress.org/ticket/51024).

### `oneOf` and `anyOf`

These are advanced keywords that allow for the JSON Schema validator to choose one
of _many_ schemas to use when validating a value. The `anyOf` keyword allows for
a value to match at least one of the given schemas. Whereas, the `oneOf` keyword
requires the value match _exactly_ one schema.

For example, this schema allows for submitting an array of “operations” to an endpoint.
Each operation can either be a “crop” or a “rotation”.

    ```notranslate
    {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "title": "Crop",
            "type": "object",
            "properties": {
              "operation": {
                "type": "string",
                "enum": [
                  "crop"
                ]
              },
              "x": {
                "type": "integer"
              },
              "y": {
                "type": "integer"
              }
            }
          },
          {
            "title": "Rotation",
            "type": "object",
            "properties": {
              "operation": {
                "type": "string",
                "enum": [
                  "rotate"
                ]
              },
              "degrees": {
                "type": "integer",
                "minimum": 0,
                "maximum": 360
              }
            }
          }
        ]
      }
    }
    ```

The REST API will loopLoop The Loop is PHP code used by WordPress to display posts.
Using The Loop, WordPress processes each post to be displayed on the current page,
and formats it according to how it matches specified criteria within The Loop tags.
Any HTML or PHP code in the Loop will be processed on each post. [https://codex.wordpress.org/The_Loop](https://codex.wordpress.org/The_Loop)
over each schema specified in the `oneOf` array and look for a match. If exactly
one schema matches, then validation will succeed. If more than one schema matches,
validation will fail. If no schemas match, then the validator will try to find the
closest matching schema and return an appropriate error message.

> operations[0] is not a valid Rotation. Reason: operations[0][degrees] must be 
> between 0 (inclusive) and 360 (inclusive)

See [#51025](https://core.trac.wordpress.org/ticket/51025).

### Expose all JSON Schema keywords in the index

When making an `OPTIONS` request to an endpoint, the REST API will return the `args`
that the route accepts. Previously, only a limited subset of JSON Schema keywords
were exposed. In WordPress 5.6, now the full list of JSON Schema keywords that the
REST API supports will be exposed. See [#51020](https://core.trac.wordpress.org/ticket/51020).

#### More specific validation error codes

When the `type` of a value is incorrect, `rest_validate_value_from_schema` now returns`
rest_invalid_type` instead of the generic `rest_invalid_param`. The validation error
code is not currently exposed to REST API clients. This would only effect direct
usages of the validation function.

## Miscellaneous

The `apiRequest` library now supports using the `PUT` and `DELETE` HTTPHTTP HTTP
is an acronym for Hyper Text Transfer Protocol. HTTP is the underlying protocol 
used by the World Wide Web and this protocol defines how messages are formatted 
and transmitted, and what actions Web servers and browsers should take in response
to various commands. methods with servers that didn’t support those methods. This
is done by making the request a `POST` request and passing the original HTTP method
in the `X-HTTP-Method-Override` headerHeader The header of your site is typically
the first thing people will experience. The masthead or header art located across
the top of your page is part of the look and feel of your website. It can influence
a visitor’s opinion about your content and you/ your organization’s brand. It may
also look different on different screen sizes.. [#43605](https://core.trac.wordpress.org/ticket/43605).

The comments controller now uses the `rest_get_route_for_post` function introduced
in WordPress 5.5 to generate the `up` response link. This function is filterable
to allow for [custom controllers to properly define](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/#registering-a-custom-post-type-with-rest-api-support)
their REST API route. [#44152](https://core.trac.wordpress.org/ticket/44152).

The REST API now supports a broader range of JSON media types. Previously, only `
application/json` was supported which prevented using subtypes like `application/
activity+json`. The REST API will now `json_decode` the body of requests using a
JSON subtype `Content-Type`. Additionally, `wp_die()` now properly sends the error
as JSON when a JSON subtype is specified in the `Accept` header. [#49404](https://core.trac.wordpress.org/ticket/49404).

_Props [@m\_butcher](https://profiles.wordpress.org/m_butcher/) for reviewing._

[#5-6](https://make.wordpress.org/core/tag/5-6/), [#dev-notes](https://make.wordpress.org/core/tag/dev-notes/),
[#rest-api](https://make.wordpress.org/core/tag/rest-api/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2020/12/08/rest-api-changes-in-wordpress-5-6/?share=linkedin)

# Post navigation

[← WordPress 5.6 RC 5](https://make.wordpress.org/core/2020/12/07/wordpress-5-6-rc-5/)

[Editor Chat Agenda: 9 December, 2020 →](https://make.wordpress.org/core/2020/12/08/editor-chat-agenda-9-december-2020/)