Skip to content

xiaojiaoyu100/cast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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