Skip to content

equinix/rest-go

Repository files navigation

Equinix REST client

Equinix REST client written in Go. Implementation is based on Resty client.

Build Status Go Report Card GoDoc GitHub


Purpose

Purpose of this module is to wrap Resty REST client with Equinix specific error handling. In addition, module adds support for paginated query requests.

Module is used by other Equinix client libraries, like ECX Fabric Go client or Network Edge Go client.

Features

  • parses Equinix standardized error response body contents
  • GetPaginated function queries for data on APIs with paginated responses. Pagination options can be configured by setting up attributes of PagingConfig

Usage

  1. Get recent equinix/rest-go module

    go get -d github.com/equinix/rest-go
  2. Create new Equinix REST client with default HTTP client

    import (
        "context"
        "net/http"
        "github.com/equinix/rest-go"
    )
    
    func main() {
      c := rest.NewClient(
           context.Background(),
           "https://api.equinix.com",
           &http.Client{})
    }
  3. Use Equinix HTTP client with Equinix APIs

     respBody := api.AccountResponse{}
     req := c.R().SetResult(&respBody)
     if err := c.Execute(req, "GET", "/ne/v1/device/account"); err != nil {
      //Equinix application error details will be included
      log.Printf("Got error: %s", err) 
     }

Debugging

Debug logging comes from Resty client and logs request and response details to stderr.

Such debug logging can be enabled by setting up EQUINIX_REST_LOG environmental variable to DEBUG