Skip to content

Add Response.ajson #1639

Answered by tomchristie
ToxicKidz asked this question in Ideas
Discussion options

You must be logged in to vote

So, this wouldn’t make sense as a counterpart because .json() doesn’t read the response body.

Let’s explain that more clearly. There’s no need for an ajson(), because this already works just fine...

r = await client.get(...)
r.json()  # There’s no I/O occurring here.

The only case where you need to explicitly perform I/O is in the streaming case.

async with client.stream(...) as r:
    await r.aread()
    r.json()  # Can only call .json once we’ve loaded the response body.

Which anyway matches the style you’d need to use in the sync case...

with client.stream(...) as r:
    r.read()
    r.json()  # Can only call .json once we’ve loaded the response body.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ToxicKidz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants