def get_param(request, name, default_value=None):
    """ Return required request param, or default_value if not found. """

    if request.body:
        if default_value is None:
            # This is required.
            if request.POST:
                # Must be a form POST.
                return request.POST[name]
            else:
                # Assume it's JSON in body of request, and it's required.
                return request.json_body[name]
        else:
            # This is optional.
            if request.POST:
                # Must be a form POST.
                return request.POST.get(name, default_value)
            else:
                # Assume it's JSON in body of request, and it's required.
                return request.json_body.get(name, default_value)
    else:
        # Assume it's uri-encoded.
        return request.params.get(name, default_value)