def http_req(blink, url='http://example.com', data=None, headers=None,
             reqtype='get', stream=False, json_resp=True, is_retry=False):
    """
    Perform server requests and check if reauthorization neccessary.

    :param blink: Blink instance
    :param url: URL to perform request
    :param data: Data to send (default: None)
    :param headers: Headers to send (default: None)
    :param reqtype: Can be 'get' or 'post' (default: 'get')
    :param stream: Stream response? True/FALSE
    :param json_resp: Return JSON response? TRUE/False
    :param is_retry: Is this a retry attempt? True/FALSE
    """
    if reqtype == 'post':
        req = Request('POST', url, headers=headers, data=data)
    elif reqtype == 'get':
        req = Request('GET', url, headers=headers)
    else:
        _LOGGER.error("Invalid request type: %s", reqtype)
        raise BlinkException(ERROR.REQUEST)

    prepped = req.prepare()

    try:
        response = blink.session.send(prepped, stream=stream, timeout=10)
        if json_resp and 'code' in response.json():
            if is_retry:
                _LOGGER.error("Cannot obtain new token for server auth.")
                return None
            else:
                headers = attempt_reauthorization(blink)
                if not headers:
                    raise exceptions.ConnectionError
                return http_req(blink, url=url, data=data, headers=headers,
                                reqtype=reqtype, stream=stream,
                                json_resp=json_resp, is_retry=True)
    except (exceptions.ConnectionError, exceptions.Timeout):
        _LOGGER.info("Cannot connect to server with url %s.", url)
        if not is_retry:
            headers = attempt_reauthorization(blink)
            return http_req(blink, url=url, data=data, headers=headers,
                            reqtype=reqtype, stream=stream,
                            json_resp=json_resp, is_retry=True)
        _LOGGER.error("Endpoint %s failed. Possible issue with Blink servers.",
                      url)
        return None

    if json_resp:
        return response.json()

    return response
Perform server requests and check if reauthorization neccessary.

    :param blink: Blink instance
    :param url: URL to perform request
    :param data: Data to send (default: None)
    :param headers: Headers to send (default: None)
    :param reqtype: Can be 'get' or 'post' (default: 'get')
    :param stream: Stream response? True/FALSE
    :param json_resp: Return JSON response? TRUE/False
    :param is_retry: Is this a retry attempt? True/FALSE