Tutorial¶
Welcome to the httpr tutorial! This guide will take you through all the features of httpr step by step.
What You'll Learn¶
This tutorial is organized into sections that build on each other:
-
Making Requests
Learn how to make HTTP requests with different methods, headers, and data.
-
Response Handling
Work with response data, headers, cookies, and status codes.
-
Authentication
Use Basic Auth, Bearer tokens, and other authentication methods.
-
Async Client
Use async/await for concurrent requests.
Prerequisites¶
Before starting, make sure you have httpr installed:
Verify the installation:
Module-Level Functions vs Client¶
httpr provides two ways to make requests:
Module-Level Functions¶
For quick, one-off requests:
Each call creates a new client internally, which is convenient but not efficient for multiple requests.
Client Instance¶
For applications making multiple requests:
import httpr
with httpr.Client() as client:
response1 = client.get("https://httpbin.org/get")
response2 = client.get("https://httpbin.org/ip")
Benefits of using a Client:
- Connection pooling: Reuses connections for better performance
- Default configuration: Set headers, auth, timeout once
- Cookie persistence: Cookies are automatically stored and sent
- Resource management: Proper cleanup with context manager
Next Steps¶
Start with Making Requests to learn the basics of sending HTTP requests.