Documentation
¶
Overview ¶
Package httpx provides some types and function helping when working with the HTTP package.
Index ¶
- Constants
- func AcceptsContentType(h http.Header, contentType string) bool
- func ContainsContentType(h http.Header, contentType string) bool
- func IsValidMethod(method string) bool
- func MarshalBody(w io.Writer, h http.Header, v interface{}) error
- func PathAt(r *http.Request, n int) (string, bool)
- func PathParts(r *http.Request) []string
- func ReadBody(r io.ReadCloser) ([]byte, error)
- func UnmarshalBody(r io.ReadCloser, h http.Header, v interface{}) error
- func WriteBody(w io.Writer, data []byte) error
Constants ¶
const ( HeaderAccept = "Accept" HeaderContentType = "Content-Type" ContentTypePlain = "text/plain" ContentTypeHTML = "text/html" ContentTypeXML = "application/xml" ContentTypeJSON = "application/json" ContentTypeURLEncoded = "application/x-www-form-urlencoded" )
Headers fields and values.
Variables ¶
This section is empty.
Functions ¶
func AcceptsContentType ¶
AcceptsContentType checks a request header accepts a given content type.
func ContainsContentType ¶
ContainsContentType checks if the header contains the given content type.
func IsValidMethod ¶
IsValidMethod returns true if the passed method is valid.
func MarshalBody ¶
MarshalBody allows to directly marshal a value into a writer depending on the content type.
func PathAt ¶
PathAt returns the nth part of the request path and true if it exists. Otherwise an empty string and false.
func PathParts ¶
PathParts splits the request path into its parts.
func ReadBody ¶
func ReadBody(r io.ReadCloser) ([]byte, error)
ReadBody retrieves the whole body out of a HTTP request or response and returns it as byte slice.
func UnmarshalBody ¶
func UnmarshalBody(r io.ReadCloser, h http.Header, v interface{}) error
UnmarshalBody parses the body data of a request or response based on the content type header stores the result in the value pointed by v. Conten types JSON and XML expect the according types as arguments, all text types expect a string, and all others too, but the data is encoded in BASE64.
Types ¶
This section is empty.
Source Files
¶
- body.go
- doc.go
- header.go
- method.go
- path.go