package rest
import "github.com/open-policy-agent/opa/plugins/rest"
Package rest implements a REST client for communicating with remote services.
Index ¶
- type Client
- func New(config []byte) (Client, error)
- func (c Client) Do(ctx context.Context, method, path string) (*http.Response, error)
- func (c Client) Service() string
- func (c Client) WithBytes(body []byte) Client
- func (c Client) WithHeader(k, v string) Client
- func (c Client) WithJSON(body interface{}) Client
- type Config
Types ¶
type Client ¶
Client implements an HTTP/REST client for communicating with remote services.
func New ¶
New returns a new Client for config.
func (Client) Do ¶
Do executes a request using the client.
func (Client) Service ¶
Service returns the name of the service this Client is configured for.
func (Client) WithBytes ¶
WithBytes returns a shallow copy of the client with the bytes set as the message body to include in the requests.
func (Client) WithHeader ¶
WithHeader returns a shallow copy of the client with a header to include the requests.
func (Client) WithJSON ¶
WithJSON returns a shallow copy of the client with the JSON value set as the message body to include the requests. This function sets the Content-Type header.
type Config ¶
type Config struct { Name string `json:"name"` URL string `json:"url"` Headers map[string]string `json:"headers"` Credentials struct { Bearer *struct { Scheme string `json:"scheme,omitempty"` Token string `json:"token"` } `json:"bearer,omitempty"` } `json:"credentials"` }
Config represents configuration for a REST client.
Source Files ¶
- Version
- v0.8.2
- Published
- Jun 22, 2018
- Platform
- js/wasm
- Imports
- 10 packages
- Last checked
- 4 minutes ago –
Tools for package owners.