-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
53 lines (46 loc) · 1.31 KB
/
basic.js
File metadata and controls
53 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Word Scramble Generator API - Basic Usage Example
*
* This example demonstrates the basic usage of the Word Scramble Generator API.
* API Documentation: https://docs.apiverve.com/ref/wordscramble
*/
const API_KEY = process.env.APIVERVE_API_KEY || 'YOUR_API_KEY_HERE';
const API_URL = 'https://api.apiverve.com/v1/wordscramble';
/**
* Make a GET request to the Word Scramble Generator API
*/
async function callWordScrambleGeneratorAPI() {
try {
const response = await fetch(API_URL, {
method: 'GET',
headers: {
'x-api-key': API_KEY
}
});
// Check if response is successful
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
// Check API response status
if (data.status === 'ok') {
console.log('✓ Success!');
console.log('Response data:', data.data);
return data.data;
} else {
console.error('✗ API Error:', data.error || 'Unknown error');
return null;
}
} catch (error) {
console.error('✗ Request failed:', error.message);
return null;
}
}
// Run the example
callWordScrambleGeneratorAPI()
.then(result => {
if (result) {
console.log('\n📊 Final Result:');
console.log(JSON.stringify(result, null, 2));
}
});