def wrap_json_params(func):
    """
    A middleware that parses the body of json requests and
    add it to the request under the `params` key.
    """

    @functools.wraps(func)
    def wrapper(request, *args, **kwargs):
        ctype, pdict = parse_header(request.headers.get('Content-Type', ''))
        if ctype == "application/json":
            request.params = json.loads(request.body.decode("utf-8")) if request.body else None
        return func(request, *args, **kwargs)
    return wrapper
A middleware that parses the body of json requests and
    add it to the request under the `params` key.