sitestudio / otest

Test SKGithubTest app
MIT License
0 stars 0 forks source link

Example Student GET call #298

Open sitestudio opened 1 month ago

sitestudio commented 1 month ago

Provide a C# example of making a STUDENT GET call.

Also show an example output.

skgithubtest[bot] commented 1 month ago
#!/bin/bash

# create a new file for the C# code
echo "using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static readonly HttpClient client = new HttpClient();

    static async Task Main()
    {
        try
        {
            // make the HTTP GET request
            HttpResponseMessage response = await client.GetAsync(\"API_URL\"); // replace with actual API URL
            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            // print the response to console
            Console.WriteLine(responseBody);
        }
        catch(HttpRequestException e)
        {
            // handle any errors
            Console.WriteLine(\"Error: {0}\", e.Message);
        }
    }
}" > Program.cs

Example output:

{
    "studentId": "1",
    "name": "John Doe",
    "grade": "A"
}