Skip to main content

One post tagged with "API"

View All Tags

· 3 min read
Josh Fraser

Overview

The Ionburst Cloud API HEAD method has been added to allow IBC S6 objects and IBC NKV secrets to be verified after upload, or queried to return information.

A HEAD request is functionally similar to a GET request; it is authenticated and requires the external reference of the object or secret to be checked. Instead of returning the specified object or secret, the HEAD request returns a status code and a response header with the size of the stored object or secret.

For full details of the HEAD method, please see the API docs for IBC S6, and IBC NKV.

Getting Started

In this tutorial we will provide examples and code snippets of how to use the new HEAD method:

  1. Using the HEAD method with ioncli
  2. Using the HEAD method with the Ionburst Cloud Go SDK

ioncli

In this example, we will upload a file, my-file.txt to IBC S6 using ioncli, then verify its size with the ioncli head command.

Creating my-file.txt:

echo "We may guard your data, but we'll never take its freedom" > my-file.txt

Uploading my-file.txt with ioncli:

ioncli --profile ioncli-example put head-example my-file.txt

Checking my-file.txt with ioncli:

ioncli --profile ioncli-example head head-example

Example output:

[hello@ioncli-example ~]$ echo "We may guard your data, but we'll never take its freedom" > my-file.txt
[hello@ioncli-example ~]$ ls -lah my-file.txt
-rw-rw-r--. 1 hello hello 57B Sep 04 13:37 my-file.txt
[hello@ioncli-example ~]$ ioncli --profile default head head-example
Size: 57

Go SDK

The following example program shows how the Ionburst Cloud Go SDK Head and HeadWithLen methods can be used:

package main
import (
"fmt"
"gitlab.com/ionburst/ionburst-sdk-go"
"os"
)
func main() {
client, err := ionburst.NewClient()
if err != nil {
fmt.Println(err)
}
ioReader, _ := os.Open("my-file.txt")
err = client.Put("head-example", ioReader, "")
if err != nil {
fmt.Println(err)
}
err = client.Head("head-example")
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Checked: %s\n", "head-example")
}
size, err := client.HeadWithLen("head-example")
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Size: %d\n", size)
}
}

Example output:

[hello@example head]$ go run main.go
Checked: head-example
Size: 57