restapi

package
v0.0.0-...-ae8e89f Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(
	fx.Provide(New),
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// Call is used to send one request to REST API endpoint. The request input will be 'method' and 'requestBody'.
	// Note that 'requestBody' is mostly used for POST. The request response and error are returned.
	Call(ctx context.Context, method *RequestMethod, requestBody []byte) ([]byte, error)
}

Client defines the interface for REST API. Different from Json RPC, parts of the parameters will be embeded into the URL. Therefore, different types of requests will query different URLs. The endpoint shared URL is stored in Config while each request method provides the parameter URL.

type ClientParams

type ClientParams struct {
	fx.In
	fxparams.Params
	Master     endpoints.EndpointProvider `name:"master"`
	Slave      endpoints.EndpointProvider `name:"slave"`
	Validator  endpoints.EndpointProvider `name:"validator"`
	Consensus  endpoints.EndpointProvider `name:"consensus"`
	HTTPClient HTTPClient                 `optional:"true"` // Injected by unit test.
}

type ClientResult

type ClientResult struct {
	fx.Out
	Master    Client `name:"master"`
	Slave     Client `name:"slave"`
	Validator Client `name:"validator"`
	Consensus Client `name:"consensus"`
}

func New

func New(params ClientParams) (ClientResult, error)

type HTTPClient

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

type HTTPError

type HTTPError struct {
	Code     int
	Response string
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type RequestMethod

type RequestMethod struct {
	Name       string
	ParamsPath string
	Timeout    time.Duration
}

RequestMethod represents a REST method, including the parameter URL and timeout. The 'Name' is just used for annotation. For example, in Aptos, the 'ParamsPath' for block 1 will be: "/blocks/by_height/1?with_transactions=true".

Directories

Path Synopsis
Package restapimocks is a generated GoMock package.
Package restapimocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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