sdk

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 4 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

dis-redirect-api SDK

Overview

The dis-redirect-api contains a Go client for interacting with the API. The client contains a methods for each API endpoint so that any Go application wanting to interact with the API can do so. Please refer to the swagger specification as the source of truth of how each endpoint works.

Example use of the API SDK

Initialise new redirect API client

package main

import (
    "context"
    redirectAPI "github.com/ONSdigital/dis-redirect-api/sdk/go"
)

func main() {
    ...
    redirectAPIClient := redirectAPI.NewClient("http://localhost:29900")
    ...
}
Hello World

Use the GetHelloWorld method to send a request to say hello. This will be removed as additional functionality is added.

...
    // Set authorisation header
    headers := make(map[header][]string)
    headers[Authorisation] = []string{"Bearer authorised-user"}

    resp, err := redirectAPIClient.GetHelloWorld(ctx, sdk.Options{sdk.Headers: headers})
    if err != nil {
        // handle error
    }

    /* If successful the resp value will be *HelloWorldReponse struct found in github.com/ONSdigital/dis-redirect-api/api package

    JSON equivalent:
    {
        "message": <value>,
    }
    */
...

Documentation

Index

Constants

View Source
const (
	// RedirectEndpoint is the endpoint for a single redirect.
	RedirectEndpoint = "%s/v1/redirects/%s"
	// RedirectsEndpoint is the listing endpoint for redirects.
	RedirectsEndpoint = "%s/v1/redirects"
)
View Source
const (
	// Authorization represents the HTTP Authorization header.
	Authorization string = request.AuthHeaderKey
)

List of available headers

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a client for interacting with the redirect API.

func NewClient

func NewClient(redirectAPIURL string) *Client

NewClient creates a new instance of Client with a given redirect api url

func NewWithHealthClient

func NewWithHealthClient(hcCli *healthcheck.Client) *Client

NewWithHealthClient creates a new instance of redirect API Client, reusing the URL and Clienter from the provided healthcheck client

func (*Client) Checker

func (cli *Client) Checker(ctx context.Context, check *health.CheckState) error

Checker calls redirect api health endpoint and returns a check object to the caller

func (*Client) DeleteRedirect added in v0.3.3

func (cli *Client) DeleteRedirect(
	ctx context.Context,
	options Options,
	id string,
) apiError.Error

DeleteRedirect deletes a redirect via the /redirects/{id} endpoint

func (*Client) GetRedirect added in v0.3.0

func (cli *Client) GetRedirect(ctx context.Context, options Options, key string) (*models.Redirect, apiError.Error)

GetRedirect gets the /redirects/{id} endpoint

func (*Client) GetRedirects added in v0.3.5

func (cli *Client) GetRedirects(ctx context.Context, options Options) (*models.Redirects, apiError.Error)

GetRedirects gets the /redirects endpoint

func (*Client) Health

func (cli *Client) Health() *healthcheck.Client

Health returns the underlying Healthcheck Client for this redirect API client

func (*Client) PutRedirect added in v0.3.2

func (cli *Client) PutRedirect(
	ctx context.Context,
	options Options,
	id string,
	payload models.Redirect,
) apiError.Error

PutRedirect updates a redirect via the /redirects/{id} endpoint

func (*Client) URL

func (cli *Client) URL() string

URL returns the URL used by this client

type Clienter added in v1.4.0

type Clienter interface {
	URL() string
	Health() *healthcheck.Client
	Checker(ctx context.Context, check *health.CheckState) error
	GetRedirect(ctx context.Context, options Options, key string) (*models.Redirect, apiError.Error)
	GetRedirects(ctx context.Context, options Options) (*models.Redirects, apiError.Error)
	PutRedirect(ctx context.Context, options Options, id string, payload models.Redirect) apiError.Error
	DeleteRedirect(ctx context.Context, options Options, id string) apiError.Error
}

Clienter is an interface defining the methods available for interacting with the redirect API.

type Options

type Options struct {
	Headers http.Header
	Query   url.Values
}

Options is a struct containing for customised options for the API client

type ResponseInfo

type ResponseInfo struct {
	// Body contains the response body as a byte slice.
	Body []byte
	// Headers contains the HTTP headers returned in the response.
	Headers http.Header
	// Status contains the HTTP status code returned in the response.
	Status int
}

ResponseInfo represents the response information returned from a call to the redirect API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL