Replace

Replacing text across content

You can replace text across the entire site by invoking the POST /@replace endpoint. The pattern can be a plain string or a regular expression:

POST /@replace HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk

{
  "pattern": "Event",
  "replacement": "Meeting"
}

Or use the client directly:

import { Client } from '@robgietema/nick';

const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({
  data: { login: 'admin', password: 'admin' },
});

const { data } = await cli.replace({
  pattern: 'Event',
  replacement: 'Meeting',
});

The API will return a list of all content items that were modified:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "@id": "http://localhost:8080/@replace",
  "changes": [
    {
      "title": "Events",
      "path": "/events",
      "fields": [
        "title"
      ]
    },
    {
      "title": "Event 1",
      "path": "/events/event-1",
      "fields": [
        "title"
      ]
    },
    {
      "title": "Event 2",
      "path": "/events/event-2",
      "fields": [
        "title"
      ]
    }
  ]
}

This site uses Just the Docs, a documentation theme for Jekyll.