Documentation
¶
Index ¶
- Constants
- Variables
- func Apply(req *http.Request, opts []RequestOption)
- func Do(ctx context.Context, client *http.Client, method, u string, ...) error
- func NewRequest(ctx context.Context, method, u string, reqBody io.Reader, opts []RequestOption) (*http.Request, error)
- func UnexpectedStatusCode(resp *http.Response) error
- func WithJSONBody(ctx context.Context, method, u string, reqBody any, opts []RequestOption) (*http.Request, error)
- type RequestOption
Constants ¶
const XBLRelyingParty = "http://xboxlive.com"
XBLRelyingParty is the relying party used for various Xbox Live services. In XSAPI Client, it will be used for requesting NSAL endpoints for current authenticated title.
Variables ¶
var DefaultLanguage = AcceptLanguage([]language.Tag{ language.AmericanEnglish, language.English, })
DefaultLanguage is an AcceptLanguage option that appends American English and English as fallback language preferences to the 'Accept-Language' header. It is intended to be appended after any caller-provided options so that it always appears as the lowest-priority suffix in the header value.
Functions ¶
func Apply ¶
func Apply(req *http.Request, opts []RequestOption)
Apply applies the given RequestOptions to the request in order. Caller-provided opts take precedence over any defaults appended after them. For example, append caller opts before defaults like append(opts, internal.DefaultLanguage) so that the caller's preferences are evaluated first.
func Do ¶
func Do(ctx context.Context, client *http.Client, method, u string, reqBody, respBody any, opts []RequestOption) error
Do sends an HTTP request to the given URL using the provided client.
If reqBody is non-nil, it is JSON-encoded and sent as the request body with the 'Content-Type' header set to 'application/json'.
If respBody is non-nil and the response status is 200 OK or 201 Created, the response body is JSON-decoded into respBody.
opts are applied to the request before it is sent. Useful options are defined in this package.
func NewRequest ¶
func NewRequest(ctx context.Context, method, u string, reqBody io.Reader, opts []RequestOption) (*http.Request, error)
NewRequest creates a new HTTP request with the given context, method, URL, and body, then applies any provided request options.
func UnexpectedStatusCode ¶
UnexpectedStatusCode returns an error describing an unexpected HTTP status code, including the request method and URL for context. The resp must be a client response because http.Response.Request is only populated on responses received by the client.
func WithJSONBody ¶
func WithJSONBody(ctx context.Context, method, u string, reqBody any, opts []RequestOption) (*http.Request, error)
WithJSONBody creates a new HTTP request with the given body JSON-encoded as the request body.
Types ¶
type RequestOption ¶
RequestOption specifies an option to be applied to an outgoing HTTP request.
Callers may accept multiple RequestOptions as a variadic or slice parameter. Options must be applied to the request using Apply.
A RequestOption must be reusable and must not hold any per-request state.
func AcceptLanguage ¶
func AcceptLanguage(tags []language.Tag) RequestOption
AcceptLanguage returns a internal.RequestOption that appends the given language tags to the 'Accept-Language' header on outgoing requests, preserving any tags already present in the header.
func ContractVersion ¶
func ContractVersion(v string) RequestOption
ContractVersion returns a RequestOption that sets the X-Xbl-Contract-Version header to the specified version string. The appropriate version depends on the target endpoint. The value 'vnext' may also be accepted for some endpoint.
func RequestHeader ¶
func RequestHeader(key, value string) RequestOption
RequestHeader returns a internal.RequestOption that sets a request header with the given name and value on outgoing requests.