rest

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start[Configuration, State any](restConnector connector.Connector[Configuration, State], options ...connector.ServeOption) error

Start wrap the connector.Start function with custom CLI

Types

type CLI

type CLI struct {
	connector.ServeCLI
	Convert command.ConvertCommandArguments `cmd:"" help:"Convert API spec to NDC schema. For example:\n ndc-rest-schema convert -f petstore.yaml -o petstore.json"`
}

CLI extends the NDC SDK with custom commands

func (CLI) Execute

func (c CLI) Execute(ctx context.Context, cmd string) error

Execute executes custom commands

type Configuration

type Configuration struct {
	Files []SchemaFile `json:"files" yaml:"files"`
}

Configuration contains required settings for the connector.

type Doer

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

Doer abstracts a HTTP client with Do method

type Option

type Option (func(*options))

Option is an interface to set custom REST connector options

func WithClient

func WithClient(client Doer) Option

WithClient sets the custom HTTP client that satisfy the Doer interface

type RESTConnector

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

RESTConnector implements the SDK interface of NDC specification

func NewRESTConnector

func NewRESTConnector(opts ...Option) *RESTConnector

NewRESTConnector creates a REST connector instance

func (*RESTConnector) GetCapabilities

func (c *RESTConnector) GetCapabilities(configuration *Configuration) schema.CapabilitiesResponseMarshaler

GetCapabilities get the connector's capabilities.

func (*RESTConnector) GetSchema

func (c *RESTConnector) GetSchema(ctx context.Context, configuration *Configuration, _ *State) (schema.SchemaResponseMarshaler, error)

GetSchema gets the connector's schema.

func (*RESTConnector) HealthCheck

func (c *RESTConnector) HealthCheck(ctx context.Context, configuration *Configuration, state *State) error

HealthCheck checks the health of the connector.

For example, this function should check that the connector is able to reach its data source over the network.

Should throw if the check fails, else resolve.

func (*RESTConnector) Mutation

func (c *RESTConnector) Mutation(ctx context.Context, configuration *Configuration, state *State, request *schema.MutationRequest) (*schema.MutationResponse, error)

Mutation executes a mutation.

func (*RESTConnector) MutationExplain

func (c *RESTConnector) MutationExplain(ctx context.Context, configuration *Configuration, state *State, request *schema.MutationRequest) (*schema.ExplainResponse, error)

MutationExplain explains a mutation by creating an execution plan.

func (*RESTConnector) ParseConfiguration

func (c *RESTConnector) ParseConfiguration(ctx context.Context, configurationDir string) (*Configuration, error)

ParseConfiguration validates the configuration files provided by the user, returning a validated 'Configuration', or throwing an error to prevents Connector startup.

func (*RESTConnector) Query

func (c *RESTConnector) Query(ctx context.Context, configuration *Configuration, state *State, request *schema.QueryRequest) (schema.QueryResponse, error)

Query executes a query.

func (*RESTConnector) QueryExplain

func (c *RESTConnector) QueryExplain(ctx context.Context, configuration *Configuration, state *State, request *schema.QueryRequest) (*schema.ExplainResponse, error)

QueryExplain explains a query by creating an execution plan.

func (*RESTConnector) TryInitState

func (c *RESTConnector) TryInitState(ctx context.Context, configuration *Configuration, metrics *connector.TelemetryState) (*State, error)

TryInitState initializes the connector's in-memory state.

For example, any connection pools, prepared queries, or other managed resources would be allocated here.

In addition, this function should register any connector-specific metrics with the metrics registry.

type RESTMetadata

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

RESTMetadata stores REST schema with handy methods to build requests

func (RESTMetadata) GetFunction

func (rm RESTMetadata) GetFunction(name string) (*rest.RESTFunctionInfo, error)

GetFunction gets the NDC function by name

func (RESTMetadata) GetProcedure

func (rm RESTMetadata) GetProcedure(name string) (*rest.RESTProcedureInfo, error)

GetProcedure gets the NDC procedure by name

type RESTMetadataCollection

type RESTMetadataCollection []RESTMetadata

RESTMetadataCollection stores list of REST metadata with helper methods

func (RESTMetadataCollection) GetFunction

func (rms RESTMetadataCollection) GetFunction(name string) (*rest.RESTFunctionInfo, error)

GetFunction gets the NDC function by name

func (RESTMetadataCollection) GetProcedure

func (rms RESTMetadataCollection) GetProcedure(name string) (*rest.RESTProcedureInfo, error)

GetProcedure gets the NDC procedure by name

type RetryableRequest added in v0.1.1

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

RetryableRequest wraps the raw request with retryable

func (*RetryableRequest) CreateRequest added in v0.1.1

func (r *RetryableRequest) CreateRequest(ctx context.Context) (*http.Request, context.CancelFunc, error)

CreateRequest creates an HTTP request with body copied

type SchemaFile

type SchemaFile struct {
	Path        string                `json:"path" yaml:"path"`
	Spec        schema.SchemaSpecType `json:"spec" yaml:"spec"`
	MethodAlias map[string]string     `json:"methodAlias" yaml:"methodAlias"`
	TrimPrefix  string                `json:"trimPrefix" yaml:"trimPrefix"`
	EnvPrefix   string                `json:"envPrefix" yaml:"envPrefix"`
}

SchemaFile represents a schema file

type State

type State struct {
	Schema *schema.NDCRestSchema
}

State is the global state which is shared for every connector request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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