API Usage

How to use the Arcsec API for database operations

The API endpoint can be called in several ways programmatically. Below are examples of how to call the API endpoint using different methods.

Using cURL

You can use the curl command to make a request to the API endpoint.

curl -X POST http://arcsec.dev/api/query \
-H "Content-Type: application/json" \
-d '{
"dbId": "your-db-id",
"query": "YOUR SQL QUERY",
"walletAddress": "your-wallet-address",
"apiKey": "your-api-key"
}'

Using JavaScript Fetch API

You can use the fetch API to make a request to the API endpoint.

const response = await fetch('http://arcsec.dev/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dbId: 'your-db-id',
query: 'YOUR SQL QUERY',
walletAddress: 'your-wallet-address',
apiKey: 'your-api-key',
}),
});
const data = await response.json();

Response Format

The API endpoint will respond with a JSON object. Below are the possible responses:

Successful Read Query

For a successful read query, the API will respond with a JSON object containing the query results. This might be SELECT queries, but could also be other types of queries like SHOW or DESCRIBE.

{
"result": [
// Array of objects representing the query results
]
}

Successful Modification Query

For a successful modification query, the API will respond with a JSON object containing the query results. This might be CREATE, INSERT, UPDATE, or DELETE queries.

{
"message": "Database updated successfully",
"newIpfsUri": "new-ipfs-uri",
"result": {
"changes": 1 // Number of rows affected
}
}

Error Response

If the API encounters an error, it will respond with a JSON object containing the error message.

{
"error": "Error message describing what went wrong"
}