Skip to content

Latest commit

 

History

History
88 lines (56 loc) · 1.66 KB

README.md

File metadata and controls

88 lines (56 loc) · 1.66 KB

cast

Build Status Go Report Card GoDoc

Cast is a http request library written in Golang.

This project is ready for production use and the master branch is always stable. But the API may be broken in the future release.

Getting started

dep ensure -add github.com/xiaojiaoyu100/cast

Usage

Generate a Cast

c, err := cast.New(cast.WithBaseURL("https://status.github.com"))

Generate a request

request := c.NewRequest()

Get

request := c.NewRequest().Get().WithPath("/api.json")
response, err := c.Do(request)

POST X-WWW-FORM-URLENCODED

request := c.NewRequest().Get().WithPath("/api.json").WithFormURLEncodedBody(body)
resp, err := c.Do(request)

POST JSON

request := c.NewRequest().Post().WithPath("/api.json").WithJSONBody(body)
response, err := c.Do(request)

POST XML

request := c.NewRequest().Post().WithPath("/api.json").WithXMLBody(body)
response, err := c.Do(request)

POST MULTIPART FORM DATA

request := c.NewRequest().Post().WithPath("/api.json").WithMultipartFormDataBody(formData)
resp, err := c.Do(request)

Timeout

c.NewRequest().WithTimeout(3 * time.Second)

Retry

cast.WithRetry(3)

Backoff

cast.WithXXXBackoffStrategy()

License

MIT License