Concorde documentation (crawl) · interactive version

Concorde decorator — @patch. @patch applies a partial update with the body from a publisher. It uses the Doc ID: docs/_decorators/patch. Keywords: Concorde, supersoniks, docs/_decorators/patch, patch, @patch, decorator, Endpoint, DataProviderKey, ApiResult, send(component), , when: "before", autoPostOnBodyMutation: false, autoPostOnBodyMutation, skipIfBodyMissing. URL: https://concorde.supersoniks.org/crawl/docs/_decorators/patch.html.

@patch

@patch applies a partial update with the body from a publisher. It uses the same model as @post: Endpoint<T>, DataProviderKey<B>, ApiResult<T>, options, and the send(component) handle.

Minimal usage

const bodyKey = new DataProviderKey<Partial<User>>("users.patch");
const patchUser = patch(new Endpoint<User>("users/42"), bodyKey);

@patchUser
@state()
payload?: ApiResult<User>;

The same decorator adapts to a method:

@patch(new Endpoint<User>("users/42"), bodyKey)
handlePatch(payload?: ApiResult<User>) {
  if (payload?.response?.ok) console.log(payload.result);
}

To run the operation again from the component:

async savePatch() {
  await patchUser.send(this);
}

send(component) returns a Promise resolved after the PATCH completes. See @post for the method-decorator form and the when: "before" option.

The PATCH is also sent automatically when the body mutates, unless autoPostOnBodyMutation: false is set. The available options are described in @post:

Pass explicit API configuration as the third argument:

@patch(endpoint, bodyKey, apiConfigurationKey)

Import

import { patch, type ApiResult } from "@supersoniks/concorde/decorators";
import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
import { Endpoint } from "@supersoniks/concorde/utils/endpoint";

See also