Skip to content

kpurdon/apir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go PkgGoDev Go Report Card codecov

apir

A simple package for making/consuming api[r] requests/responses.

Installation

go get github.com/kpurdon/apir

Getting Started

Initialize a Client

client := requester.NewClient("myservice")
client.MustAddAPI("otherservice", discoverer.NewDirect("http://foo.com/api"),
	requester.WithRetry(),
	requester.WithContentType(requester.ApplicationJSON),
)

Create a Request

req, err := client.NewRequest(ctx, "otherservice", http.MethodGet, "/", nil)
if err != nil {
    // an error occured trying to make the request
    // handle the error
}

Execute the Request

var (
   data struct{}
   errData struct{}
)
ok, err := client.Execute(req, &data, &errData)
if err != nil {
    // an error occured trying to executre the request
    // handle the error
    return
}
if !ok {
    // we made the request, but got a >= 400 status code
    // examine errData for error details
    return
}

// the request was made and returned a < 400 status code
// examine data for the response

About

A simple package for making/consuming api[r] requests/responses.

Topics

Resources

License

Stars

Watchers

Forks

Languages