HttpDo

package module
v0.0.0-...-b56a5e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: LGPL-2.1 Imports: 5 Imported by: 0

README

HttpDo

A simple HTTP client wrapper around the standard library for golang, because said standard library felt clunky to me. May contain bugs or other issues. This is just a simple side-project without any priority.

Install
go get github.com/RegenJoho/HttpDo

and import with

import "github.com/RegenJoho/HttpDo"
Examples
Run a simple GET Request, for example a webhook:
err := HttpDo.New().GET().Url("http://example.com/your-url").Run().Err()
POST request with json body:
err := HttpDo.New().POST().MarshalJSON(yourStruct).Run().Err()

Please note that this also works with xml, in that case use MarshalXML instead. Behind the scenes the encoding/json and encoding/xml is used, so keep in mind that your structs need to have the proper tags.

Receive data from a request:
err := request.GET().Url("http://example.com/your-url").Run().Err()
if err != nil {
	panic(err)
}
data := YourStruct{}
err = request.UnmarshalJSONResponse(&data)
if err != nil {
	panic(err)
}

As above, the same is possible with xml using UnmarshalXMLResponse.

Custom HTTP request method
err := HttpDo.New().Method("your-method").Url("http://example.com/your-url").Run().Err()

The standard HTTP request headers are also provided on their own, but using this anything is possible.

Limitations
  • If one part errors out, everything will error. This is simply a limitation of only checking for errors at the end.
  • If you forget an essential part, like for example the URL, it will error out at runtime, but your compiler or editor will not scream at you.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpDo

type HttpDo struct {
	StatusCode   int
	ResponseBody io.ReadCloser
	// contains filtered or unexported fields
}

func New

func New() *HttpDo

func (*HttpDo) CONNECT

func (h *HttpDo) CONNECT() *HttpDo

Sets the HTTP Request Method to CONNECT.

func (*HttpDo) DELETE

func (h *HttpDo) DELETE() *HttpDo

Sets the HTTP Request Method to DELETE

func (*HttpDo) Err

func (h *HttpDo) Err() error

func (*HttpDo) GET

func (h *HttpDo) GET() *HttpDo

Sets the HTTP Request Method to GET.

func (*HttpDo) HEAD

func (h *HttpDo) HEAD() *HttpDo

Sets the HTTP Request Method to HEAD.

func (*HttpDo) MarshalJSON

func (h *HttpDo) MarshalJSON(v any) *HttpDo

func (*HttpDo) MarshalXML

func (h *HttpDo) MarshalXML(v any) *HttpDo

func (*HttpDo) Method

func (h *HttpDo) Method(method string) *HttpDo

Sets the HTTP Request Method.

func (*HttpDo) OPTIONS

func (h *HttpDo) OPTIONS() *HttpDo

Sets the HTTP Request Method to OPTIONS.

func (*HttpDo) PATCH

func (h *HttpDo) PATCH() *HttpDo

Sets the HTTP Request Method to PATCH.

func (*HttpDo) POST

func (h *HttpDo) POST() *HttpDo

Sets the HTTP Request Method to POST.

func (*HttpDo) PUT

func (h *HttpDo) PUT() *HttpDo

Sets the HTTP Request Method to PUT.

func (*HttpDo) Run

func (h *HttpDo) Run() *HttpDo

func (*HttpDo) TRACE

func (h *HttpDo) TRACE() *HttpDo

Sets the HTTP Request Method to TRACE.

func (*HttpDo) UnmarshalJSONResponse

func (h *HttpDo) UnmarshalJSONResponse(v any) error

func (*HttpDo) UnmarshalXMLResponse

func (h *HttpDo) UnmarshalXMLResponse(v any) (any, error)

func (*HttpDo) Url

func (h *HttpDo) Url(url string) *HttpDo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL