resty

package module
v0.0.0-...-96ff8f7 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: GPL-3.0 Imports: 8 Imported by: 2

README

resty

resty is a generic JSON REST API client package.

Examples

client := resty.NewClient("http://todolist.com")

// call Get & Post and handle response yourself
bytes, err := client.Post("/api/todo", &Todo{Name: "Take the bins out", Due: time.Now()})
bytes, err := client.Get("/api/todos")

// use generic functions to marshal/unmarshal the response
saved, err := resty.Post[Todo, Todo](client, "/api/todo", &Todo{Name: "Take the bins out", Due: time.Now()})
todos, err := resty.Get[[]Todo](client, "/api/todos")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(filepath string, url string) error

Downloads the file at given url to the path specified, or fails if it can't.

func Get

func Get[T any](c Client, uri string) (T, error)

shim - pure function acting as a method/delegate to client.http.get to allow generics

func Post

func Post[T, U any](c Client, uri string, req T) (U, error)

shim - pure function acting as a method/delegate to client.post to allow generics

Types

type Client

type Client interface {
	Post(uri string, body any) ([]byte, error)
	Get(uri string) ([]byte, error)
}

func NewClient

func NewClient(opts ...ClientOption) Client

type ClientOption

type ClientOption func(*client)

func WithBaseUrl

func WithBaseUrl(baseUrl string) ClientOption

func WithHttpClient

func WithHttpClient(hc HttpClient) ClientOption

type HttpClient

type HttpClient interface {
	Do(*http.Request) (*http.Response, error)
}

Inteface of http.Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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