Skip to content

Update httpcore interface - #296

Merged
lovelydinosaur merged 15 commits into
masterfrom
update-core-interface
Apr 21, 2021
Merged

Update httpcore interface#296
lovelydinosaur merged 15 commits into
masterfrom
update-core-interface

Conversation

@lovelydinosaur

@lovelydinosaurlovelydinosaur commented Mar 26, 2021

Copy link
Copy Markdown
Contributor

To align with encode/httpx#1522

  • request -> handle_request, arequest -> handle_async_request
  • ext -> extensions
  • reason -> reason_phrase
  • http_version, reason_phrase -> bytes
  • headers is no longer optional
  • stream is no longer optional
  • extensions are no longer optional
  • httpcore.PlainByteStream() -> httpcore.ByteStream()

The httpcore interface then matches the HTTPX 0.18 Transport API.

Readme example after this change looks like this:


Quickstart

Here's an example of making an HTTP GET request using httpcore...

withhttpcore.SyncConnectionPool() ashttp:
status_code, headers, stream, extensions=http.handle_request(
method=b'GET',
url=(b'https', b'example.org', 443, b'/'),
headers=[(b'host', b'example.org'), (b'user-agent', b'httpcore')]
stream=httpcore.ByteStream(b''),
extensions={}
)
body=stream.read()
print(status_code, body)

Or, using async...

asyncwithhttpcore.AsyncConnectionPool() ashttp:
status_code, headers, stream, extensions=awaithttp.handle_async_request(
method=b'GET',
url=(b'https', b'example.org', 443, b'/'),
headers=[(b'host', b'example.org'), (b'user-agent', b'httpcore')],
stream=httpcore.ByteStream(b''),
extensions={}
)
body=awaitstream.aread()
print(status_code, body)

@lovelydinosaur
lovelydinosaur marked this pull request as ready for review April 20, 2021 14:57
Comment threadREADME.md Outdated
Comment threadREADME.md Outdated
@lovelydinosaur

Copy link
Copy Markdown
ContributorAuthor

Right, let's push on, push on.

@lovelydinosaur
lovelydinosaur merged commit c8d93d0 into masterApr 21, 2021
@lovelydinosaur
lovelydinosaur deleted the update-core-interface branch April 21, 2021 11:20
@lovelydinosaurlovelydinosaur mentioned this pull request Apr 21, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@lovelydinosaur