-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aiohttp.ClientSession with methods.
- `base_url` parameter: to simplify reusing the session with different methods. - `json` parameter.
- Loading branch information
Showing
3 changed files
with
106 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
micropython/uaiohttpclient/clientsession_methods_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import uaiohttpclient as aiohttp | ||
import asyncio | ||
|
||
|
||
async def main(): | ||
async with aiohttp.ClientSession("http://httpbin.org") as session: | ||
async with session.get("/get") as resp: | ||
assert resp.status == 200 | ||
rget = await resp.text() | ||
print(f"GET: {rget.decode()}") | ||
async with session.post("/post", json={"foo": "bar"}) as resp: | ||
assert resp.status == 200 | ||
rpost = await resp.text() | ||
print(f"POST: {rpost.decode()}") | ||
async with session.put("/put", data=b"data") as resp: | ||
assert resp.status == 200 | ||
rput = await resp.json() | ||
print("PUT: ", rput) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters