# mrequests

This is a variant of the `urequests` module from `micropython-lib` with a few
extensions:

* Response headers can optionally be saved in the response object.
* The `Response` class for response objects can be substituted by a custom response class.
* Support for HTTP basic auth (requires `ubinascii` module).
* Support for responses with chunked transfer encoding.
* Respects `Content-length` header in response.
* `Response` objects have a `save` method, to save the response body to
  a file, reading the response data and writing the file in small chunks.

Otherwise the API remains the same.

# mrequests

This is a variant of the [urequests] module from [micropython-lib] with a few
extensions:


## Features

* Response headers can optionally be saved in the response object.
* The `Response` class for response objects can be substituted by a custom
  response class.
* Support for HTTP basic auth (requires `ubinascii` module).
* Support for responses with chunked transfer encoding.
* Respects `Content-length` header in response.
* `Response` objects have a `save` method to save the response body to
  a file, reading the response data and writing the file in small chunks.

Otherwise the API remains the same.


## Example

```py
>>> import mrequests as requests

>>> r = requests.get("http://httpbin.org/get",
                     headers={"Accept": "application/json"})
>>> print(r)
<Response object at 7f6f91631be0>
>>> print(r.content)
b'{\n  "args": {}, \n  "headers": {\n    "Accept": "application/json", \n
"Host": "httpbin.org", \n    "X-Amzn-Trace-Id": "Root=1-[redacted]"\n  }, \n
"origin": "[redacted]", \n  "url": "http://httpbin.org/get"\n}\n'
>>> print(r.text)
{
  "args": {},
  "headers": {
    "Accept": "application/json",
    "Host": "httpbin.org",
    "X-Amzn-Trace-Id": "Root=1-[redacted]"
  },
  "origin": "[redacted]",
  "url": "http://httpbin.org/get"
}

>>> print(r.json())
{'url': 'http://httpbin.org/get', 'headers': {'X-Amzn-Trace-Id':
'Root=1-[redacted]', 'Host': 'httpbin.org', 'Accept': 'application/json'},
'args': {}, 'origin': '[redacted]'}
>>> r.close()
```

It is mandatory to close response objects as soon as you finished working with
them. On MicroPython platforms without full-fledged OS, not doing so may lead
to resource leaks and malfunction.


[micropython-lib]: https://github.com/micropython/micropython-lib
[urequests]: https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.py

Add simple HTTP GET example to readme
Add simple HTTP GET example to readme

Signed-off-by: Christopher Arndt <711c73f64afdce07b7e38039a96d2224209e9a6c@chrisarndt.de>
