-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.cs
More file actions
80 lines (70 loc) · 2.63 KB
/
basic.cs
File metadata and controls
80 lines (70 loc) · 2.63 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* 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
*/
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Linq;
namespace APIVerve.Examples
{
class WordScrambleGeneratorExample
{
private static readonly string API_KEY = Environment.GetEnvironmentVariable("APIVERVE_API_KEY") ?? "YOUR_API_KEY_HERE";
private static readonly string API_URL = "https://api.apiverve.com/v1/wordscramble";
/// <summary>
/// Make a GET request to the Word Scramble Generator API
/// </summary>
static async Task<JsonDocument> CallWordScrambleGeneratorAPI()
{
try
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", API_KEY);
var response = await client.GetAsync(API_URL);
// Check if response is successful
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var data = JsonDocument.Parse(responseBody);
// Check API response status
if (data.RootElement.GetProperty("status").GetString() == "ok")
{
Console.WriteLine("✓ Success!");
Console.WriteLine("Response data: " + data.RootElement.GetProperty("data"));
return data;
}
else
{
var error = data.RootElement.TryGetProperty("error", out var errorProp)
? errorProp.GetString()
: "Unknown error";
Console.WriteLine($"✗ API Error: {error}");
return null;
}
}
catch (HttpRequestException e)
{
Console.WriteLine($"✗ Request failed: {e.Message}");
return null;
}
}
static async Task Main(string[] args)
{
Console.WriteLine("📤 Calling Word Scramble Generator API...\n");
var result = await CallWordScrambleGeneratorAPI();
if (result != null)
{
Console.WriteLine("\n📊 Final Result:");
Console.WriteLine(result.RootElement.GetProperty("data"));
}
else
{
Console.WriteLine("\n✗ API call failed");
}
}
}
}