How the requests.Builder works
mainThe core of the library is the requests.Builder type, which provides a fluent API for building and sending HTTP requests. Instead of the verbose boilerplate required by net/http, you use method chaining to declaratively describe your request.
Key characteristics:
- Fluent API: Methods return a pointer to the same builder, allowing chaining.
- Automatic Resource Management: It automatically handles closing the response body.
- Default Validation: It checks that response status codes are in the 2XX range by default.
- Context Required: Every request must be executed using
.Fetch(ctx), wherectxis acontext.Context.
err := requests.
URL("http://example.com").
ToString(&s).
Fetch(ctx)