Multipart
To send multipart/form-data
request, pass an object to multipart=
param
Send two files
request = reqsnaked.Request(
"POST", "https://httpbin.org/anything",
multipart=reqsnaked.Multipart(
reqsnaked.Part(
"foo", b"000"
filename="foo.txt",
mime="text/plain"
),
reqsnaked.Part(
"bar", b"111",
filename="bar.txt",
mime="text/plain"
)
),
)
Full code preview
import asyncio
import reqsnaked
async def main():
client = reqsnaked.Client()
request = reqsnaked.Request(
"POST", "https://httpbin.org/anything",
multipart=reqsnaked.Multipart(
reqsnaked.Part("foo", b"000", filename="foo.txt",
mime="text/plain"),
reqsnaked.Part("bar", b"111", filename="bar.txt",
mime="text/plain")
),
)
response = await client.send(request)
content = await response.json()
# httpbin returns query string we passed in the response
content.show()
asyncio.run(main())
{
"bar": "111",
"foo": "000"
}
Todo
Currently, only raw bytes and strings are supported for content, io
objects are coming soon