package http
import "github.com/IBM/fp-go/http"
Index ¶
- Constants
- Variables
- func GetBody(resp *H.Response) io.ReadCloser
- func GetHeader(resp *H.Response) H.Header
- func ParseMediaType(mediaType string) E.Either[error, ParsedMediaType]
- func StatusCodeError(resp *H.Response) error
- type FullResponse
- type HttpError
- func (r *HttpError) Body() []byte
- func (r *HttpError) Error() string
- func (r *HttpError) Headers() H.Header
- func (r *HttpError) StatusCode() int
- func (r *HttpError) String() string
- func (r *HttpError) URL() *url.URL
- type ParsedMediaType
Constants ¶
const (
HeaderContentType = "Content-Type"
)
Variables ¶
var ( // ValidateResponse validates an HTTP response and returns an [E.Either] if the response is not a success ValidateResponse = E.FromPredicate(isValidStatus, StatusCodeError) // ValidateJSONResponse checks if an HTTP response is a valid JSON response ValidateJSONResponse = F.Flow2( E.Of[error, *H.Response], E.ChainFirst(F.Flow5( GetHeader, R.Lookup[H.Header](HeaderContentType), O.Chain(A.First[string]), E.FromOption[string](errors.OnNone("unable to access the [%s] header", HeaderContentType)), E.ChainFirst(validateJSONContentTypeString), ))) // ValidateJsonResponse checks if an HTTP response is a valid JSON response // // Deprecated: use [ValidateJSONResponse] instead ValidateJsonResponse = ValidateJSONResponse )
Functions ¶
func GetBody ¶
func GetBody(resp *H.Response) io.ReadCloser
func GetHeader ¶
func ParseMediaType ¶
func ParseMediaType(mediaType string) E.Either[error, ParsedMediaType]
ParseMediaType parses a media type into a tuple
func StatusCodeError ¶
StatusCodeError creates an instance of HttpError filled with information from the response
Types ¶
type FullResponse ¶
FullResponse represents a full http response, including headers and body
type HttpError ¶
type HttpError struct {
// contains filtered or unexported fields
}
func (*HttpError) Body ¶
func (*HttpError) Error ¶
Error fulfills the error interface
func (*HttpError) Headers ¶
func (*HttpError) StatusCode ¶
func (*HttpError) String ¶
func (*HttpError) URL ¶
type ParsedMediaType ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
http/builder | |
http/content | |
http/form | |
http/headers |
- Version
- v1.0.151 (latest)
- Published
- Nov 23, 2024
- Platform
- linux/amd64
- Imports
- 13 packages
- Last checked
- 4 months ago –
Tools for package owners.