Skip to content

About

Webitel OpenAPI Client for Go

Topics

Resources

Stars

0 stars

Watchers

4 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

Webitel HTTP OpenAPI Client for Go

This HTTP Go client for Webitel is generated from Webitel's OpenAPI specification using swagger for Go.

Generate the client

Once bingo & swagger are installed (see Dependencies), generate the client for all Webitel APIs, with the following make command:

make generate-client

This runs the Swagger generation command.

To generate the client for a specific Webitel API, find the name of its tag and model in the Webitel OpenAPI specification. Then, set those as environment variables and run the command to generate it:

export API_TAG=CalendarService
export MODEL=engineCalendar
make generate-client

How to use custom templates

In order to generate the client, go-swagger uses default templates. These templates can be customised to add custom configuration that are applied each time the client is generated.

For more information, check out the go-swagger docs on how to use custom templates. The default template definitions for the client can be found in go-swagger/generator/templates/client/.

In this project, the custom templates can be found in templates/. They are provided to the generation command through the flag --template-dir=templates.

The custom templates provide added functionality for things such as authentication, TLS/SSL, retries, and custom error handling.

Build the client

Configuration

The client has the following friendly configuration options:

import goapi "github.com/webitel/webitel-openapi-client-go/client"

cfg := &goapi.TransportConfig{
    // Host is the doman name or IP address of the host that serves the API.
    Host:       "dev.webitel.com",
    
    // BasePath is the URL prefix for all API paths, relative to the host root.
    BasePath:   "/api",
    
    // Schemes are the transfer protocols used by the API (http or https).
    Schemes:    []string{"http"},
    
    // APIKey is an optional API key or service account token.
    APIKey:     os.Getenv("WEBITEL_ACCESS_TOKEN"),
    
    // TLSConfig provides an optional configuration for a TLS client
    TLSConfig:  &tls.Config{},
    
    // NumRetries contains the optional number of attempted retries
    NumRetries: 3,
    
    // RetryTimeout sets an optional time to wait before retrying a request
    RetryTimeout: 0,
    
    // RetryStatusCodes contains the optional list of status codes to retry
    // Use "x" as a wildcard for a single digit (default: [429, 5xx])
    RetryStatusCodes: []string{"420", "5xx"},
    
    // HTTPHeaders contains an optional map of HTTP headers to add to each request
    HTTPHeaders: map[string]string{},
}

client := goapi.NewHTTPClientWithConfig(strfmt.Default, cfg)

Examples

Checkout how the Webitel Terraform Provider initialises and uses the client here.

The goswagger documentation have more information about how to build a client.

About

Webitel OpenAPI Client for Go

Topics

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages