Repository navigation
Make a httpx GET request with data body #2912
Replies: 3 comments
|
Use the general import httpx
async with httpx.AsyncClient() as client:
response = await client.request(
"GET",
"http://localhost:8000/user/",
params={"limit": 10},
headers={"accept": "application/json"},
json=[{"item_type": "user", "skip": 0}],
)
|
|
GET is not supposed to have a body by design. Actually, there has been a new RFC with a new method called QUERY, that is basically a GET with a body |
|
In To send a 1. Top-Level Synchronous Requestimport httpx
params = {"limit": 10}
headers = {"accept": "application/json"}
json_data = [{"item_type": "user", "skip": 0}]
response = httpx.request(
"GET",
"http://localhost:8000/user/",
params=params,
headers=headers,
json=json_data,
)2. With a Client Session (Recommended for Connection Pooling)import httpx
with httpx.Client() as client:
response = client.request(
"GET",
"http://localhost:8000/user/",
params=params,
headers=headers,
json=json_data,
)3. Explicit Request Constructionwith httpx.Client() as client:
req = client.build_request(
"GET",
"http://localhost:8000/user/",
params=params,
headers=headers,
json=json_data,
)
response = client.send(req)(Note: Passing |
Uh oh!
There was an error while loading. Please reload this page.
When I do a curl request for GET endpoint of a REST API, I would go it like this
Directly translated into
requests, I would getNow for my test environment I am going to use
httpx'sAsyncClient, but I cannot find a way to use the data part, i.e.,[{"item_type": "user", "skip": 0}], in a get request.It would be terrific, if you know how to address this.
All reactions