Skip to content

Go API Client Example

This example demonstrates how to send an authenticated HTTP request to the Core API using Go’s standard library.

The example uses the built-in net/http package and Bearer token authentication to communicate with the API.


Overview

Go provides a lightweight and powerful HTTP client through the standard library, making external dependencies unnecessary for most API integrations.

This example demonstrates how to:

  • Create an HTTP request
  • Add authentication headers
  • Send the request using http.Client
  • Read and display the response

Example Request

package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseURL := "https://website.core-software.co.uk"
    token := "YOUR_TOKEN_HERE"

    req, err := http.NewRequest(
        "GET",
        baseURL+"/api/v1",
        nil,
    )

    if err != nil {
        panic(err)
    }

    req.Header.Set(
        "Authorization",
        "Bearer "+token,
    )

    req.Header.Set(
        "Content-Type",
        "application/json",
    )

    client := &http.Client{}

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }

    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    fmt.Printf("Status: %d\n", resp.StatusCode)
    fmt.Printf("Body: %s\n", body)
}

Notes

  • Replace YOUR_TOKEN_HERE with a valid API token before running the example
  • The example sends a simple GET request to the API root endpoint
  • Authentication is provided using the Authorization: Bearer header
  • The response status code and body are printed to the console
  • Error handling is intentionally minimal for demonstration purposes