/admin/servers/parity
POST SYNCConfigure or change the parity server for the QMail system.
POST /api/admin/servers/parity
Description
The `/admin/servers/parity` endpoint allows administrators to configure or update the parity server designation. The parity server provides redundancy and error recovery capabilities for the RAIDA network. This endpoint validates that the specified server exists before applying the configuration.
Administrative Endpoint
This is an administrative endpoint that modifies system configuration. Ensure you have proper authorization before making changes to the parity server settings.
Request Body
The request must include a JSON body specifying the server ID to designate as the parity server.
| Parameter | Type | Required | Description |
|---|---|---|---|
server_id |
string | Yes | The unique identifier of the server to set as parity (e.g., "RAIDA1"). |
Example Request Body
{
"server_id": "RAIDA1"
}
Response
Returns a 200 OK response on success, or 404 Not Found if the specified server does not exist.
Success Response Properties
status
string
The operation status. Will be
"success" on successful configuration.
server_id
string
The server ID that was configured as the parity server.
message
string
A human-readable confirmation message.
Example Success Response (200 OK)
{
"status": "success",
"server_id": "RAIDA1",
"message": "Parity server successfully set to RAIDA1."
}
Example Error Response (404 Not Found)
{
"status": "error",
"message": "Server with ID 'RAIDA99' not found."
}
Try It Out
Examples
JavaScript (async/await)
const API_BASE = 'http://localhost:8080/api';
async function setParityServer(serverId) {
try {
const response = await fetch(`${API_BASE}/admin/servers/parity`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ server_id: serverId })
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || `HTTP error! status: ${response.status}`);
}
console.log(`Success: ${data.message}`);
console.log(`Parity server set to: ${data.server_id}`);
return data;
} catch (error) {
console.error('Error setting parity server:', error);
throw error;
}
}
// Set RAIDA1 as the parity server
setParityServer('RAIDA1');
cURL
# Set RAIDA1 as the parity server
curl -X POST "http://localhost:8080/api/admin/servers/parity" \
-H "Content-Type: application/json" \
-d '{
"server_id": "RAIDA1"
}'
# Expected success response:
# {"status":"success","server_id":"RAIDA1","message":"Parity server successfully set to RAIDA1."}
Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
const ApiBase = "http://localhost:8080/api"
type ParityRequest struct {
ServerID string `json:"server_id"`
}
type ParitySetResponse struct {
Status string `json:"status"`
ServerID string `json:"server_id,omitempty"`
Message string `json:"message"`
}
func setParityServer(serverID string) (*ParitySetResponse, error) {
payload := ParityRequest{ServerID: serverID}
payloadBytes, err := json.Marshal(payload)
if err != nil {
return nil, err
}
url := fmt.Sprintf("%s/admin/servers/parity", ApiBase)
resp, err := http.Post(url, "application/json", bytes.NewBuffer(payloadBytes))
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result ParitySetResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed: %s", result.Message)
}
return &result, nil
}
func main() {
result, err := setParityServer("RAIDA1")
if err != nil {
panic(err)
}
fmt.Printf("Status: %s\n", result.Status)
fmt.Printf("Message: %s\n", result.Message)
fmt.Printf("Parity Server: %s\n", result.ServerID)
}