sdk

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 3

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  = "%s/v1/redirects/%s"
	RedirectsEndpoint = "%s/v1/redirects"
)
View Source
const (
	// List of available headers
	Authorization string = request.AuthHeaderKey
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

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 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    []byte
	Headers http.Header
	Status  int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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