// newRequest creates an API request. A relative URL path can be provided in
// path, in which case it is resolved relative to the apiVersionPath of the
// Client. Relative URL paths should always be specified without a preceding
// slash.
// If v is supplied, the value will be JSONAPI encoded and included as the
// request body. If the method is GET, the value will be parsed and added as
// query parameters.
newRequest creates an API request. A relative URL path can be provided in
path, in which case it is resolved relative to the apiVersionPath of the
Client. Relative URL paths should always be specified without a preceding
slash.
If v is supplied, the value will be JSONAPI encoded and included as the
request body. If the method is GET, the value will be parsed and added as
query parameters.
// newRequest creates an API request . A relative URL path can be provided in // path in which case it is resolved relative to the apiVersionPath of the // Client . Relative URL paths should always be specified without a preceding // slash . // If v is supplied the value will be JSONAPI encoded and included as the // request body . If the method is GET the value will be parsed and added as // query parameters .
func (c *Client) newRequest(method, path string, v interface{}) (*retryablehttp.Request, error) {
	u, err := c.baseURL.Parse(path)
	if err != nil {
		return nil, err
	}
	reqHeaders := make(http.Header)
	reqHeaders.Set("Authorization", "Bearer "+c.token)
	var body interface{}
	switch method {
	case "GET":
		reqHeaders.Set("Accept", "application/vnd.api+json")
		if v != nil {
			q, err := query.Values(v)
			if err != nil {
				return nil, err
			}
			u.RawQuery = q.Encode()
		}
	case "DELETE", "PATCH", "POST":
		reqHeaders.Set("Accept", "application/vnd.api+json")
		reqHeaders.Set("Content-Type", "application/vnd.api+json")
		if v != nil {
			buf := bytes.NewBuffer(nil)
			if err := jsonapi.MarshalPayloadWithoutIncluded(buf, v); err != nil {
				return nil, err
			}
			body = buf
		}
	case "PUT":
		reqHeaders.Set("Accept", "application/json")
		reqHeaders.Set("Content-Type", "application/octet-stream")
		body = v
	}
	req, err := retryablehttp.NewRequest(method, u.String(), body)
	if err != nil {
		return nil, err
	}
	for k, v := range c.headers {
		req.Header[k] = v
	}
	for k, v := range reqHeaders {
		req.Header[k] = v
	}
	return req, nil
}
func ( c * Client ) newRequest ( method , path string , v interface { } ) ( * retryablehttp . Request , error ) { u , err := c . baseURL . Parse ( path ) if err != nil { return nil , err } reqHeaders := make ( http . Header ) reqHeaders . Set ( " " , " " + c . token ) var body interface { } switch method { case " " : reqHeaders . Set ( " " , " " ) if v != nil { q , err := query . Values ( v ) if err != nil { return nil , err } u . RawQuery = q . Encode ( ) } case " " , " " , " " : reqHeaders . Set ( " " , " " ) reqHeaders . Set ( " " , " " ) if v != nil { buf := bytes . NewBuffer ( nil ) if err := jsonapi . MarshalPayloadWithoutIncluded ( buf , v ) ; err != nil { return nil , err } body = buf } case " " : reqHeaders . Set ( " " , " " ) reqHeaders . Set ( " " , " " ) body = v } req , err := retryablehttp . NewRequest ( method , u . String ( ) , body ) if err != nil { return nil , err } for k , v := range c . headers { req . Header [ k ] = v } for k , v := range reqHeaders { req . Header [ k ] = v } return req , nil }
newRequest creates an API request.
newRequest creates an API request .
// Create a request specific headers map. // Set the default headers. // Set the request specific headers.