Documentation
¶
Overview ¶
Package apiclient talks to the API of a locally running roji server.
Requests connect to an address the server listens on and carry the dashboard hostname in the Host header. That avoids depending on *.localhost DNS resolution while still reaching the dashboard virtual host, which is the only one that serves the /_api endpoints.
Index ¶
- func Get(settings *config.Settings, path string, timeout time.Duration) (*http.Response, error)
- func NewClient(timeout time.Duration) *http.Client
- func NewRequest(settings *config.Settings, path string) (*http.Request, error)
- func SendJSON(ctx context.Context, client *http.Client, settings *config.Settings, ...) (*http.Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get sends a GET request to the local roji API endpoint at path. The caller is responsible for closing the response body.
func NewClient ¶
NewClient returns an HTTP client for talking to the local roji server. TLS verification is disabled because roji serves a self-signed certificate.
Verifying against roji's own CA was considered and left out. The connection is to an address on this machine (loopback unless bind says otherwise) and carries no secrets, while verification would break the CLI whenever the certificate does not cover the dashboard hostname, has expired, or the CA is not readable by the user running the CLI.
func NewRequest ¶
NewRequest builds a GET request against the local roji API endpoint at path, using the resolved settings for the listen address and the dashboard hostname.
func SendJSON ¶ added in v1.4.0
func SendJSON(ctx context.Context, client *http.Client, settings *config.Settings, method, path string, payload any) (*http.Response, error)
SendJSON sends a request with an optional JSON body to the local roji API endpoint at path, through client. A nil payload sends no body. The caller is responsible for closing the response body.
The client is the caller's so that one making many requests — `roji run` renewing its route — can keep a connection open instead of making a new one, TLS handshake included, every time.
Types ¶
This section is empty.