C# API Client Example
This example demonstrates how to send an authenticated HTTP request to the
Core API using .NET’s built-in HttpClient.
The request uses Bearer token authentication to communicate with the API.
Overview
HttpClient is the standard .NET class for sending HTTP requests and receiving
HTTP responses.
It supports:
- Asynchronous request handling
- Custom headers and authentication
- Full control over request and response processing
Example Request
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
class ApiQuery
{
static async Task Main()
{
string baseUrl = "https://website.core-software.co.uk";
string token = "YOUR_TOKEN_HERE";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response =
await client.GetAsync($"{baseUrl}/api/v1");
Console.WriteLine($"Status: {response.StatusCode}");
string body = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Body: {body}");
}
}
Notes
- Replace
YOUR_TOKEN_HEREwith a valid API token before running the example - The request is sent asynchronously using
async/await - The example performs a simple
GETrequest to the API root endpoint - The response status code and response body are printed to the console
- Error handling has been omitted for simplicity