// NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the
// BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the
// value pointed to by body is JSON encoded and included in as the request body.
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the
BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the
value pointed to by body is JSON encoded and included in as the request body.
// NewRequest creates an API request . A relative URL can be provided in urlStr which will be resolved to the // BaseURL of the Client . Relative URLS should always be specified without a preceding slash . If specified the // value pointed to by body is JSON encoded and included in as the request body .
func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error) {
	rel, err := url.Parse(urlStr)
	if err != nil {
		return nil, err
	}
	u := c.BaseURL.ResolveReference(rel)
	buf := new(bytes.Buffer)
	if body != nil {
		err = json.NewEncoder(buf).Encode(body)
		if err != nil {
			return nil, err
		}
	}
	req, err := http.NewRequest(method, u.String(), buf)
	if err != nil {
		return nil, err
	}
	req.SetBasicAuth(c.username, c.password)
	req.Header.Add("Content-Type", mediaType)
	req.Header.Add("Accept", mediaType)
	req.Header.Add("User-Agent", c.UserAgent)
	return req, nil
}
func ( c * Client ) NewRequest ( ctx context . Context , method , urlStr string , body interface { } ) ( * http . Request , error ) { rel , err := url . Parse ( urlStr ) if err != nil { return nil , err } u := c . BaseURL . ResolveReference ( rel ) buf := new ( bytes . Buffer ) if body != nil { err = json . NewEncoder ( buf ) . Encode ( body ) if err != nil { return nil , err } } req , err := http . NewRequest ( method , u . String ( ) , buf ) if err != nil { return nil , err } req . SetBasicAuth ( c . username , c . password ) req . Header . Add ( " " , mediaType ) req . Header . Add ( " " , mediaType ) req . Header . Add ( " " , c . UserAgent ) return req , nil }
NewRequest creates an API request.
NewRequest creates an API request .