API Routes Examples

Example API routes using Arcsec's API endpoint for common database operations.

Overview

This page provides examples of how to create API routes in your application using Arcsec's "/api/query" endpoint. These examples demonstrate common database operations such as inserting new users, retrieving data for display, and updating records.

Example API Routes

1. Insert New User

This route demonstrates how to insert a new user's login and password into a 'users' table.

const response = await fetch('http://arcsec.dev/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dbId: 'your-db-id',
query: 'INSERT INTO users (walletAddress, password) VALUES (?, ?)',
params: ['user-wallet-address', 'user-password'],
walletAddress: 'your-wallet-address',
apiKey: 'your-api-key',
}),
});
const data = await response.json();

2. Retrieve User Data

This route demonstrates how to retrieve user data from the 'users' table based on the user's wallet address.

const response = await fetch('http://arcsec.dev/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dbId: 'your-db-id',
query: 'SELECT FROM users WHERE walletAddress = ?',
params: ['user-wallet-address'],
walletAddress: 'your-wallet-address',
apiKey: 'your-api-key',
}),
});
const data = await response.json();

3. Update User Data

This route demonstrates how to update a user's password in the 'users' table based on the user's wallet address.

const response = await fetch('http://arcsec.dev/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dbId: 'your-db-id',
query: 'UPDATE users SET password = ? WHERE walletAddress = ?',
params: ['new-password', 'user-wallet-address'],
walletAddress: 'your-wallet-address',
apiKey: 'your-api-key',
}),
});
const data = await response.json();

4. Delete User Data

This route demonstrates how to delete a user's data from the 'users' table based on the user's wallet address.

const response = await fetch('http://arcsec.dev/api/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
dbId: 'your-db-id',
query: 'DELETE FROM users WHERE walletAddress = ?',
params: ['user-wallet-address'],
walletAddress: 'your-wallet-address',
apiKey: 'your-api-key',
}),
});
const data = await response.json();