kbhttp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 9 Imported by: 0

README

kbhttp

Go Reference

A simple http client for Katabole, primarily for tests.

Documentation

Overview

Package kbhttp provides a simple HTTP client for testing with Katabole.

For a canonical usage example see https://github.com/katabole/kbexample/tree/main/actions

Example:

client := kbhttp.NewClient(kbhttp.ClientConfig{BaseURL: "http://localhost:3000/"})

var user models.User
if err := f.Client.GetJSON("/users/12345", &user); err != nil {
	t.Fatalf("failed to get user: %v", err)
}

user.Name = "Tom"
if err := f.Client.PutJSON("/users/12345", user, nil); err != nil {
	t.Fatalf("failed to update user: %v", err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config ClientConfig) *Client

func (*Client) DeleteJSON

func (c *Client) DeleteJSON(urlPath string, target any) error

func (*Client) DeletePage

func (c *Client) DeletePage(urlPath string) (string, error)

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) DoJSON

func (c *Client) DoJSON(req *http.Request, target any) error

func (*Client) DoPage

func (c *Client) DoPage(req *http.Request) (string, error)

func (*Client) GetJSON

func (c *Client) GetJSON(urlPath string, target any) error

func (*Client) GetPage

func (c *Client) GetPage(urlPath string) (string, error)

func (*Client) PostJSON

func (c *Client) PostJSON(urlPath string, input any, target any) error

func (*Client) PostPage

func (c *Client) PostPage(urlPath string, input url.Values) (string, error)

func (*Client) PutJSON

func (c *Client) PutJSON(urlPath string, input any, target any) error

func (*Client) PutPage

func (c *Client) PutPage(urlPath string, input url.Values) (string, error)

type ClientConfig

type ClientConfig struct {
	BaseURL *url.URL
}

Jump to

Keyboard shortcuts

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