Installation
Installation of each StatusCake API SDK should be performed through the respective package manager, or directly from GitHub where appropriate. This guide will prefer the use of a dependency manager unless otherwise stated.
Use the following steps to install the StatusCake API SDK for the desired language:
Some SDK are currently in alpha and will not be given support at this time. We are currently working to deliver stable releases for each of these projects. Read more about alpha releases here.
- Go
- JavaScript (alpha)
- Python (alpha)
- Ruby (alpha)
go get github.com/StatusCakeDev/statuscake-go
npm install -D statuscake-js
pip install statuscake-py
bundle add statuscake-rb
Create a Client
Once the desired SDK(s) is installed the next step is to create an authenticated API client. You can view and manage your API tokens from the StatusCake account panel.
API tokens must be kept private. In the event that one is exposed a new one should be generated.
- Go
- JavaScript (alpha)
- Python (alpha)
- Ruby (alpha)
package main
import (
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))
}
import 'isomorphic-fetch';
import {
Configuration,
} from '@statuscake/statuscake-js';
const config = new Configuration({
headers: {
'Authorization': `Bearer ${apiToken}`,
},
});
from statuscake import ApiClient
client = ApiClient(
header_name='Authorization',
header_value='Bearer %s' % api_token,
)
require 'statuscake'
client = StatusCake::ApiClient.new
# Constructing these options is a temporary fix until a client wide
# authentication mechanism has been realised.
opts = { header_params: { 'Authorization' => "Bearer #{api_token}" } }
List Uptime Checks
With the API client configured you may make requests to the StatusCake API using the available methods. In this document we will list all uptime checks for the given workspace.
- Go
- JavaScript (alpha)
- Python (alpha)
- Ruby (alpha)
package main
import (
"context"
"fmt"
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
bearer := credentials.NewBearerWithStaticToken("my-api-token")
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))
res, err := client.ListUptimeTests(context.Background()).Execute()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", res.Data)
}
import 'isomorphic-fetch';
import {
Configuration,
UptimeApi,
} from '@statuscake/statuscake-js';
const config = new Configuration({
headers: {
'Authorization': `Bearer ${apiToken}`,
},
});
const service = new UptimeApi(config);
service.listUptimeTests()
.then((tests) => console.log(JSON.stringify(tests)))
.catch(console.log);
from statuscake import ApiClient
from statuscake.apis import UptimeApi
client = ApiClient(
header_name='Authorization',
header_value='Bearer %s' % api_token,
)
service = UptimeApi(api_client=client)
tests = service.list_uptime_tests()
print(tests)
require 'statuscake'
client = StatusCake::ApiClient.new
# Constructing these options is a temporary fix until a client wide
# authentication mechanism has been realised.
opts = { header_params: { 'Authorization' => "Bearer #{api_token}" } }
service = StatusCake::UptimeApi.new(client)
tests = service.list_uptime_tests(opts)
puts tests
Next steps
There are many other methods available within each SDK to manage StatusCake monitoring resource that are not covered in this document. See the respective SDK GitHub repositories for example usage.
Next learn about configuration options available in the SDKs.