{"modulePath":"github.com/apimatic/go-core-runtime","version":"v0.0.29","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package https\n\nPackage https Copyright (c) APIMatic. All rights reserved.\n\nPackage https provides utilities and structures for handling API requests and responses using the HTTP protocol. Copyright (c) APIMatic. All rights reserved.\n\nPackage https Copyright (c) APIMatic. All rights reserved.\n\n## Constants\n\n```go\nconst (\n\tIndexed = iota\n\tUnIndexed\n\tPlain\n\tCsv\n\tTsv\n\tPsv\n)\n```\nConstants for different request retry options.\n\n```go\nconst ACCEPT_HEADER = \"accept\"\n```\n\n```go\nconst AND_AUTH = \"and\"\n```\n\n```go\nconst AUTHENTICATION_ERROR = \"Authentication Error\"\n```\n\n```go\nconst AUTHORIZATION_HEADER = \"authorization\"\n```\n\n```go\nconst CONTENT_LENGTH_HEADER = \"content-length\"\n```\n\n```go\nconst CONTENT_TYPE_HEADER = \"content-type\"\n```\n\n```go\nconst FORM_URLENCODED_CONTENT_TYPE = \"application/x-www-form-urlencoded\"\n```\n\n```go\nconst INTERNAL_ERROR = \"Internal Error\"\n```\n\n```go\nconst JSON_CONTENT_TYPE = \"application/json\"\n```\n\n```go\nconst MULTIPART_CONTENT_TYPE = \"multipart/form-data\"\n```\n\n```go\nconst OCTET_STREAM_CONTENT_TYPE = \"application/octet-stream\"\n```\n\n```go\nconst OR_AUTH = \"or\"\n```\n\n```go\nconst SINGLE_AUTH = \"single\"\n```\n\n```go\nconst TEXT_CONTENT_TYPE = \"text/plain; charset=utf-8\"\n```\n\n```go\nconst XML_CONTENT_TYPE = \"application/xml\"\n```\n\n## Variables\n\n```go\nvar ArraySerializationOptionStrings = [...]string{\n\t\"Indexed\",\n\t\"UnIndexed\",\n\t\"Plain\",\n\t\"Csv\",\n\t\"Tsv\",\n\t\"Psv\",\n}\n```\n\n## Functions\n\n```go\nfunc AddQuery(req *http.Request, key, value string)\n```\n\n```go\nfunc FormatAny(value any) string\n```\n\n```go\nfunc FromFastHttpRequest(\n\tmethodBytes []byte,\n\turl string,\n\tbodyBytes []byte,\n\theaderFunc func(setFunc func(k, v []byte)),\n\trequestURIBytes []byte,\n\tvisitAllCookieFunc func(func(key, value []byte)),\n) (*http.Request, error)\n```\n\n```go\nfunc MergeHeaders(headers, headersToMerge map[string]string)\n```\nMergeHeaders merges the headers from the \\`headersToMerge\\` map into the \\`headers\\` map. If a header with a key already exists in the \\`headers\\` map, it is skipped and not overwritten.\n\n```go\nfunc ReadRequestBody(req *http.Request) ([]byte, error)\n```\n\n```go\nfunc SetHeaders(headers map[string]string, name, value string)\n```\nSetHeaders sets the header name and value in the provided headers map.\n\n```go\nfunc Unescape(token string) string\n```\nUnescape unescapes a json pointer reference token string to the original representation\n\n## Types\n\n```go\ntype ApiError struct {\n\tRequest    http.Request\n\tStatusCode int\n\tHeaders    http.Header\n\tBody       []byte\n\tMessage    string\n}\n```\nApiError is the base struct for all error responses from the server. It holds information about the original HTTP request, the status code, headers, and response body.\n\n```go\nfunc (a ApiError) Error() string\n```\n\n```go\nfunc (a ApiError) String() string\n```\n\n```go\ntype ApiResponse[T any] struct {\n\tData     T              `json:\"data\"`\n\tResponse *http.Response `json:\"response\"`\n}\n```\nApiResponse is a generic struct that represents an API response containing data and the HTTP response. The \\`Data\\` field holds the data of any type \\`T\\` returned by the API. The \\`Response\\` field contains the underlying HTTP response associated with the API call.\n\n```go\nfunc NewApiResponse[T any](data T, response *http.Response) ApiResponse[T]\n```\nNewApiResponse creates a new instance of ApiResponse. It takes the \\`data\\` of type \\`T\\` and the \\`response\\` as parameters, and returns an ApiResponse\\[T] struct.\n\n```go\ntype ArraySerializationOption int\n```\nArraySerializationOption represents the type for request array serialization options.\n\n```go\ntype AuthGroup struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewAndAuth(authGroup1, authGroup2 AuthGroup, moreAuthGroups ...AuthGroup) AuthGroup\n```\n\n```go\nfunc NewAuth(key string) AuthGroup\n```\n\n```go\nfunc NewOrAuth(authGroup1, authGroup2 AuthGroup, moreAuthGroups ...AuthGroup) AuthGroup\n```\n\n```go\ntype AuthInterface interface {\n\tValidate() error\n\tAuthenticator() HttpInterceptor\n}\n```\n\n```go\ntype CallBuilder interface {\n\tAppendPath(path string)\n\tAppendTemplateParam(param string)\n\tAppendTemplateParams(params ...any)\n\tAppendErrors(errors map[string]ErrorBuilder[error])\n\tBaseUrl(arg string)\n\tMethod(httpMethodName string)\n\n\tAccept(acceptHeaderValue string)\n\tContentType(contentTypeHeaderValue string)\n\tHeader(name string, value any)\n\tCombineHeaders(headersToMerge map[string]string)\n\tQueryParam(name string, value any)\n\tQueryParams(parameters map[string]any)\n\tQueryParamWithArraySerializationOption(name string, value any, option ArraySerializationOption)\n\tQueryParamsWithArraySerializationOption(parameters map[string]any, option ArraySerializationOption)\n\n\tFormParam(name string, value any)\n\tFormParams(parameters map[string]any)\n\tFormParamWithArraySerializationOption(name string, value any, opt ArraySerializationOption)\n\tFormParamsWithArraySerializationOption(parameters map[string]any, opt ArraySerializationOption)\n\n\tFormData(fields FormParams)\n\n\tText(body string)\n\tFileStream(file FileWrapper)\n\tJson(data any)\n\n\tInterceptRequest(interceptor func(httpRequest *http.Request) *http.Request)\n\n\tCall() (*HttpContext, error)\n\tCallAsJson() (*json.Decoder, *http.Response, error)\n\tCallAsText() (string, *http.Response, error)\n\tCallAsStream() ([]byte, *http.Response, error)\n\tAuthenticate(authGroup AuthGroup)\n\tRequestRetryOption(option RequestRetryOption)\n\tArraySerializationOption(option ArraySerializationOption)\n\tLogger(sdkLogger logger.SdkLoggerInterface)\n\t// contains filtered or unexported methods\n}\n```\nCallBuilder is an interface that defines methods for building and executing HTTP requests for API calls.\n\n```go\ntype CallBuilderFactory func(ctx context.Context, httpMethod, path string) CallBuilder\n```\nCallBuilderFactory is a function type used to create CallBuilder instances for making API calls.\n\n```go\nfunc CreateCallBuilderFactory(\n\tbaseUrlProvider baseUrlProvider,\n\tauth map[string]AuthInterface,\n\thttpClient HttpClient,\n\tretryConfig RetryConfiguration,\n\toption ArraySerializationOption,\n) CallBuilderFactory\n```\nCreateCallBuilderFactory creates a new CallBuilderFactory function which creates a new CallBuilder using the provided inputs\n\n```go\ntype ErrorBuilder[T error] struct {\n\tMessage          string\n\tTemplatedMessage string\n\tUnmarshaller     func(ApiError) T\n}\n```\n\n```go\nfunc (eb ErrorBuilder[T]) Build(httpctx HttpContext) error\n```\n\n```go\ntype FileWrapper struct {\n\tFile        []byte\n\tFileName    string\n\tFileHeaders http.Header\n}\n```\nFileWrapper is a struct that represents a file along with its metadata such as the file content, file name, and file headers.\n\n```go\nfunc GetFile(filePath string) (FileWrapper, error)\n```\nGetFile retrieves a file from the given filePath and returns it as a FileWrapper. It makes an HTTP GET request to the filePath to fetch the file's content and metadata. OR It uses os.ReadFile to read the file's content and metadata.\n\n```go\nfunc GetFileWithContentType(filePath string, contentType string) (FileWrapper, error)\n```\nGetFileWithContentType retrieves a file from the given filePath using GetFile and returns it as a FileWrapper. It also sets the provided \"content-type\" in the file headers.\n\n```go\nfunc (f FileWrapper) String() string\n```\n\n```go\ntype FormParam struct {\n\tKey     string\n\tValue   any\n\tHeaders http.Header\n}\n```\nFormParam is a struct that represents a key-value pair for form parameters. It contains the key, value, and headers associated with the form parameter.\n\n```go\ntype FormParams []FormParam\n```\nFormParams represents a collection of FormParam objects.\n\n```go\nfunc (fp *FormParams) Add(formParam FormParam)\n```\nAdd appends a FormParam to the FormParams collection.\n\n```go\ntype HttpCallExecutor func(request *http.Request) HttpContext\n```\nHttpCallExecutor is a function type that represents the execution of an HTTP call and returns the HTTP context.\n\n```go\nfunc CallHttpInterceptors(\n\tinterceptors []HttpInterceptor,\n\tclient HttpCallExecutor,\n) HttpCallExecutor\n```\nCallHttpInterceptors chains multiple HTTP interceptors together to create a composite HttpCallExecutor. The interceptors are applied in the reverse order of their appearance in the interceptors slice. Each interceptor gets a chance to process the request before passing it to the next interceptor in the chain, and finally, the original HttpCallExecutor is called to execute the HTTP call. The composite HttpCallExecutor is returned, which includes the logic of all the interceptors.\n\n```go\ntype HttpClient struct {\n\t// contains filtered or unexported fields\n}\n```\nHttpClient is an implementation of the HttpClientInterface.\n\n```go\nfunc NewHttpClient(httpConfig HttpConfiguration) HttpClient\n```\nNewHttpClient creates a new HttpClient with the provided HttpConfiguration and returns it. The HttpConfiguration is used to set configurations like timeout, transport and retry configuration settings for the HTTP client.\n\n```go\nfunc (c *HttpClient) Execute(request *http.Request) (*http.Response, error)\n```\nExecute sends an HTTP request using the HttpClient and returns the HTTP response or an error.\n\n```go\ntype HttpClientInterface interface {\n\tExecute(request *http.Request) *http.Response\n}\n```\nHttpClientInterface defines an interface for an HTTP client that can execute HTTP requests and return HTTP responses.\n\n```go\ntype HttpConfiguration struct {\n\t// contains filtered or unexported fields\n}\n```\nHttpConfiguration holds the configuration options for the HTTP client.\n\n```go\nfunc NewHttpConfiguration(options ...HttpConfigurationOptions) HttpConfiguration\n```\nNewHttpConfiguration creates a new HttpConfiguration with the provided options and returns it. The options parameter allows setting different configuration options for the HTTP client.\n\n```go\nfunc (h *HttpConfiguration) RetryConfiguration() RetryConfiguration\n```\nRetryConfiguration returns the configured retry configuration for the HTTP client.\n\n```go\nfunc (h *HttpConfiguration) Timeout() float64\n```\nTimeout returns the configured timeout value for the HTTP client.\n\n```go\nfunc (h *HttpConfiguration) Transport() http.RoundTripper\n```\nTransport returns the configured custom HTTP transport for the HTTP client.\n\n```go\ntype HttpConfigurationOptions func(*HttpConfiguration)\n```\nHttpConfigurationOptions is a function type that takes a pointer to HttpConfiguration as input and modifies it.\n\n```go\nfunc WithRetryConfiguration(retryConfig RetryConfiguration) HttpConfigurationOptions\n```\nWithRetryConfiguration sets the retry configuration for the HTTP client.\n\n```go\nfunc WithTimeout(timeout float64) HttpConfigurationOptions\n```\nWithTimeout sets the timeout for the HTTP client.\n\n```go\nfunc WithTransport(transport http.RoundTripper) HttpConfigurationOptions\n```\nWithTransport sets the custom HTTP transport for the HTTP client.\n\n```go\ntype HttpContext struct {\n\tRequest  *http.Request\n\tResponse *http.Response\n}\n```\nHttpContext represents the HTTP request and response.\n\n```go\nfunc PassThroughInterceptor(\n\treq *http.Request,\n\tnext HttpCallExecutor,\n) HttpContext\n```\nPassThroughInterceptor is an HTTP interceptor that passes the request to the next HttpCallExecutor in the chain. It does not modify the request or response and acts as a no-operation interceptor.\n\n```go\nfunc (ctx *HttpContext) GetResponseBody() ([]byte, error)\n```\n\n```go\ntype HttpInterceptor func(request *http.Request, next HttpCallExecutor) HttpContext\n```\nHttpInterceptor is a function type that represents an HTTP interceptor, which intercepts and processes an HTTP call.\n\n```go\ntype RequestRetryOption int\n```\nRequestRetryOption represents the type for request retry options.\n\n```go\nconst (\n\tDefault RequestRetryOption = iota\n\tEnable\n\tDisable\n)\n```\nConstants for different request retry options.\n\n```go\nfunc (r RequestRetryOption) String() string\n```\nString returns the string representation of the RequestRetryOption.\n\n```go\ntype RetryConfiguration struct {\n\t// contains filtered or unexported fields\n}\n```\nRetryConfiguration contains the settings for request retry behavior.\n\n```go\nfunc NewRetryConfiguration(options ...RetryConfigurationOptions) RetryConfiguration\n```\nNewRetryConfiguration creates a new RetryConfiguration instance with the provided options.\n\n```go\nfunc (r *RetryConfiguration) BackoffFactor() int64\n```\nBackoffFactor returns the backoff factor for exponential backoff.\n\n```go\nfunc (r *RetryConfiguration) GetRetryWaitTime(\n\tmaxWaitTime time.Duration,\n\tretryCount int64,\n\tresponse *http.Response,\n\ttimeoutError error) time.Duration\n```\nGetRetryWaitTime calculates the wait time for the next retry attempt.\n\n```go\nfunc (r *RetryConfiguration) HttpMethodsToRetry() []string\n```\nHttpMethodsToRetry returns the list of HTTP methods to retry on.\n\n```go\nfunc (r *RetryConfiguration) HttpStatusCodesToRetry() []int64\n```\nHttpStatusCodesToRetry returns the list of HTTP status codes to retry on.\n\n```go\nfunc (r *RetryConfiguration) MaxRetryAttempts() int64\n```\nMaxRetryAttempts returns the maximum number of retry attempts allowed.\n\n```go\nfunc (r *RetryConfiguration) MaximumRetryWaitTime() time.Duration\n```\nMaximumRetryWaitTime returns the maximum wait time before giving up retrying.\n\n```go\nfunc (r *RetryConfiguration) RetryInterval() time.Duration\n```\nRetryInterval returns the interval between retries.\n\n```go\nfunc (r *RetryConfiguration) RetryOnTimeout() bool\n```\nRetryOnTimeout returns whether to retry on timeouts.\n\n```go\nfunc (r *RetryConfiguration) ShouldRetry(retryRequestOption RequestRetryOption, httpMethod string) bool\n```\nShouldRetry determines if the request should be retried based on the RetryConfiguration and request HTTP method.\n\n```go\ntype RetryConfigurationOptions func(*RetryConfiguration)\n```\nRetryConfigurationOptions represents a function that modifies RetryConfiguration settings.\n\n```go\nfunc WithBackoffFactor(backoffFactor int64) RetryConfigurationOptions\n```\nWithBackoffFactor sets the backoff factor for exponential backoff.\n\n```go\nfunc WithHttpMethodsToRetry(httpMethodsToRetry []string) RetryConfigurationOptions\n```\nWithHttpMethodsToRetry sets the list of HTTP methods to retry on.\n\n```go\nfunc WithHttpStatusCodesToRetry(httpStatusCodesToRetry []int64) RetryConfigurationOptions\n```\nWithHttpStatusCodesToRetry sets the list of HTTP status codes to retry on.\n\n```go\nfunc WithMaxRetryAttempts(maxRetryAttempts int64) RetryConfigurationOptions\n```\nWithMaxRetryAttempts sets the maximum number of retry attempts allowed.\n\n```go\nfunc WithMaximumRetryWaitTime(maximumRetryWaitTime time.Duration) RetryConfigurationOptions\n```\nWithMaximumRetryWaitTime sets the maximum wait time before giving up retrying.\n\n```go\nfunc WithRetryInterval(retryInterval time.Duration) RetryConfigurationOptions\n```\nWithRetryInterval sets the interval between retries.\n\n```go\nfunc WithRetryOnTimeout(retryOnTimeout bool) RetryConfigurationOptions\n```\nWithRetryOnTimeout sets whether to retry on timeouts.\n\n","path":"github.com/apimatic/go-core-runtime/https","name":"https","synopsis":"Package https Copyright (c) APIMatic.","isRedistributable":true}
