func (c *HTTPRESTClient) Post(ctx context.Context, path path.Path, headers http.Header, body, result interface{}) (RESTResponse, error) {
	buffer := new(bytes.Buffer)
	if err := json.NewEncoder(buffer).Encode(body); err != nil {
		return RESTResponse{}, errors.Trace(err)
	}

	req, err := http.NewRequestWithContext(ctx, "POST", path.String(), buffer)
	if err != nil {
		return RESTResponse{}, errors.Annotate(err, "can not make new request")
	}

	// Compose the request headers.
	req.Header = make(http.Header)
	req.Header.Set("Accept", JSON)
	req.Header.Set("Content-Type", JSON)
	req.Header = c.composeHeaders(req.Header)

	// Add any headers specific to this request (in sorted order).
	keys := make([]string, 0, len(headers))
	for k := range headers {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		for _, v := range headers[k] {
			req.Header.Add(k, v)
		}
	}

	resp, err := c.transport.Do(req)
	if err != nil {
		return RESTResponse{}, errors.Trace(err)
	}
	defer func() { _ = resp.Body.Close() }()

	// Parse the response.
	if err := httprequest.UnmarshalJSONResponse(resp, result); err != nil {
		return RESTResponse{}, errors.Annotate(err, "charm hub client post")
	}
	return RESTResponse{
		StatusCode: resp.StatusCode,
	}, nil
}
// Post makes a POST request to the given path in the CharmHub (not
// including the host name or version prefix but including a leading /),
// parsing the result as JSON into the given result value, which should
// be a pointer to the expected data, but may be nil if no result is
// desired.
Post makes a POST request to the given path in the CharmHub (not
including the host name or version prefix but including a leading /),
parsing the result as JSON into the given result value, which should
be a pointer to the expected data, but may be nil if no result is
desired.
// Post makes a POST request to the given path in the CharmHub ( not // including the host name or version prefix but including a leading / ) // parsing the result as JSON into the given result value which should // be a pointer to the expected data but may be nil if no result is // desired .
func (c *HTTPRESTClient) Post(ctx context.Context, path path.Path, headers http.Header, body, result interface{}) (RESTResponse, error) {
	buffer := new(bytes.Buffer)
	if err := json.NewEncoder(buffer).Encode(body); err != nil {
		return RESTResponse{}, errors.Trace(err)
	}
	req, err := http.NewRequestWithContext(ctx, "POST", path.String(), buffer)
	if err != nil {
		return RESTResponse{}, errors.Annotate(err, "can not make new request")
	}
	req.Header = make(http.Header)
	req.Header.Set("Accept", JSON)
	req.Header.Set("Content-Type", JSON)
	req.Header = c.composeHeaders(req.Header)
	keys := make([]string, 0, len(headers))
	for k := range headers {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		for _, v := range headers[k] {
			req.Header.Add(k, v)
		}
	}
	resp, err := c.transport.Do(req)
	if err != nil {
		return RESTResponse{}, errors.Trace(err)
	}
	defer func() { _ = resp.Body.Close() }()
	if err := httprequest.UnmarshalJSONResponse(resp, result); err != nil {
		return RESTResponse{}, errors.Annotate(err, "charm hub client post")
	}
	return RESTResponse{
		StatusCode: resp.StatusCode,
	}, nil
}
func ( c * HTTPRESTClient ) Post ( ctx context . Context , path path . Path , headers http . Header , body , result interface { } ) ( RESTResponse , error ) { buffer := new ( bytes . Buffer ) if err := json . NewEncoder ( buffer ) . Encode ( body ) ; err != nil { return RESTResponse { } , errors . Trace ( err ) } req , err := http . NewRequestWithContext ( ctx , " " , path . String ( ) , buffer ) if err != nil { return RESTResponse { } , errors . Annotate ( err , " " ) } req . Header = make ( http . Header ) req . Header . Set ( " " , JSON ) req . Header . Set ( " " , JSON ) req . Header = c . composeHeaders ( req . Header ) keys := make ( [ ] string , 0 , len ( headers ) ) for k := range headers { keys = append ( keys , k ) } sort . Strings ( keys ) for _ , k := range keys { for _ , v := range headers [ k ] { req . Header . Add ( k , v ) } } resp , err := c . transport . Do ( req ) if err != nil { return RESTResponse { } , errors . Trace ( err ) } defer func ( ) { _ = resp . Body . Close ( ) } ( ) if err := httprequest . UnmarshalJSONResponse ( resp , result ) ; err != nil { return RESTResponse { } , errors . Annotate ( err , " " ) } return RESTResponse { StatusCode : resp . StatusCode , } , nil }
Post makes a POST request to the given path in the CharmHub (not
including the host name or version prefix but including a leading /),
parsing the result as JSON into the given result value, which should
be a pointer to the expected data, but may be nil if no result is
desired.
Post makes a POST request to the given path in the CharmHub ( not including the host name or version prefix but including a leading / ) parsing the result as JSON into the given result value which should be a pointer to the expected data but may be nil if no result is desired .
// Compose the request headers. // Add any headers specific to this request (in sorted order). // Parse the response.