/locations/{path}

GET DELETE SYNC

Select or delete a specific data location.

GET /api/v1/locations/{path}
Alias: /set-active-location/{path}
DELETE /api/v1/locations/{path}
Alias: /remove-data-location/{path}

Description

This endpoint allows you to manage a specific data location by its path. You can select a location to make it active (GET) or remove it from the configuration (DELETE).

URL-Safe Base64 Path

The {path} parameter in the URL must be a URL-safe base64 encoded string of the absolute file system path.


GET /locations/{path}

Sets the specified data location as the active one for the application. All subsequent operations will use this location.

Response

Returns a `200 OK` with no content upon success.


DELETE /locations/{path}

Removes a data location from the application's configuration.

This Does Not Delete Files

This operation only removes the location from the application's list. It does not delete the actual directory or its contents from your file system.

Response

Returns a `200 OK` with no content upon success.


Examples

JavaScript: Select a Location

const apiHost = 'http://localhost:8006';

async function selectLocation(path) {
    // The path must be base64 encoded to be used in the URL.
    const encodedPath = btoa(path);
    await fetch(`${apiHost}/api/v1/locations/${encodedPath}`);
    console.log(`Location "${path}" selected.`);
}

// selectLocation('/Users/user/new_cloudcoin_data');

JavaScript: Delete a Location

async function deleteLocation(path) {
    // The path must be base64 encoded.
    const encodedPath = btoa(path);
    await fetch(`${apiHost}/api/v1/locations/${encodedPath}`, { method: 'DELETE' });
    console.log(`Location "${path}" deleted.`);
}

// deleteLocation('/Users/user/old_cloudcoin_data');

cURL: Select a Location

# First, base64 encode your path. The '-n' flag for echo is important.
B64_PATH=$(echo -n "/Users/user/new_data" | base64)

# Use the variable in the GET request to select the location.
curl -v -X GET "http://localhost:8006/api/v1/locations/$B64_PATH"

cURL: Delete a Location

# First, base64 encode the path of the location to delete.
B64_PATH_TO_DELETE=$(echo -n "/Users/user/old_data" | base64)

# Use the variable in the DELETE request.
curl -v -X DELETE "http://localhost:8006/api/v1/locations/$B64_PATH_TO_DELETE"

Go: Select a Location

package main

import (
    "encoding/base64"
    "fmt"
    "log"
    "net/http"
)

const apiHost = "http://localhost:8006/api/v1"

// selectLocation sets a location to be the active one.
func selectLocation(path string) {
    encodedPath := base64.URLEncoding.EncodeToString([]byte(path))
    
    resp, err := http.Get(fmt.Sprintf("%s/locations/%s", apiHost, encodedPath))
    if err != nil {
        log.Fatalf("Failed to make request: %v", err)
    }
    defer resp.Body.Close()

    if resp.StatusCode == http.StatusOK {
        fmt.Printf("Successfully selected location: %s\n", path)
    } else {
        log.Fatalf("Failed to select location, status: %s", resp.Status)
    }
}

Go: Delete a Location

package main

import (
    "encoding/base64"
    "fmt"
    "log"
    "net/http"
)

// deleteLocation removes a location from the configuration.
func deleteLocation(path string) {
    encodedPath := base64.URLEncoding.EncodeToString([]byte(path))
    
    req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/locations/%s", apiHost, encodedPath), nil)
    if err != nil {
        log.Fatalf("Failed to create request: %v", err)
    }

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        log.Fatalf("Failed to execute request: %v", err)
    }
    defer resp.Body.Close()

    if resp.StatusCode == http.StatusOK {
        fmt.Printf("Successfully deleted location: %s\n", path)
    } else {
        log.Fatalf("Failed to delete location, status: %s", resp.Status)
    }
}