![]() ![]() I first became familiar with the experience of using specialized transports in testing when I was working on a Ruby project that uses VCR as an easy way to mock out calls to external HTTP services in tests. ![]() This is crucial for testing any kind of third party API. In this case, it lets us test our MailChimp API client programmatically without making any actual API requests to MailChimp. A transport can be anything that fulfills the http.RoundTripper interface of taking requests in and putting responses and errors out. This lets users set custom timeouts and cookie jars, but more importantly lets users set custom transports. ![]() Each call to V3.ListCampaigns() just clones the builder and has everything it needs to make a fully authenticated request.Īn important thing that the requests library does is allow for overriding the http.Client used for making a request. The list ID is passed to the API as a query parameter along with a bunch of other parameters, so requests lets you add a query parameter without stripping any existing parameters listed in the base URL.Ī nice thing about the requests.Builder type is that it is often possible to store everything needed for making and authenticating a request directly inside the builder itself, so there’s no need to store the base URL and API key separately as strings alongside the HTTP client. Similarly, MailChimp protects its API endpoints with Basic Auth, which as a commonly used HTTP header, requests has a convenience method for. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |