Copy / Move
Copying an object
To copy a content object send a POST
request to the /@copy
endpoint at the destinations url with the source object specified in the request body. The source object can be specified either by path.
POST /news/@copy HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Content-Type: application/json
{
"source": "/events/event-1"
}
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.copyContent({
token: login.data.token,
path: '/news/@copy',
data: {
source: '/events/event-1',
},
});
If the copy operation succeeds, the server will respond with status 200 (OK) and return the new and old url of the copied object.
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"source": "http://localhost:8080/events/event-1",
"target": "http://localhost:8080/news/event-1"
}
]
Moving an object
To move a content object send a POST
request to the /@move
endpoint at the destinations url with the source object specified in the request body. The source object can be specified either by path.
POST /news/@move HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Content-Type: application/json
{
"source": "/events/event-1"
}
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.moveContent({
token: login.data.token,
path: '/news/@copy',
data: {
source: '/events/event-1',
},
});
If the move operation succeeds, the server will respond with status 200 OK
and return the new and old url of the moved object.
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"source": "http://localhost:8080/events/event-1",
"target": "http://localhost:8080/news/event-1"
}
]
Copying/moving multiple objects
Multiple objects can be moved/copied by giving a list of sources.
POST /news/@copy HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Content-Type: application/json
{
"source": [
"/events",
"/users"
]
}
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.copyContent({
token: login.data.token,
path: '/news/@copy',
data: {
source: ['/events', '/users'],
},
});
If the operation succeeds, the server will respond with status 200 OK
and return the new and old urls for each copied/moved object.
HTTP/1.1 200 OK
Content-Type: application/json
[
{
"source": "http://localhost:8080/events",
"target": "http://localhost:8080/news/events"
},
{
"source": "http://localhost:8080/users",
"target": "http://localhost:8080/news/users"
}
]