Return a Flask ``Response`` object containing a
    JSON representation of *resource*.

    :param resource: The resource to act as the basis of the response
179230
def jsonify(resource):
    

    response = flask.jsonify(resource.to_dict())
    response = add_link_headers(response, resource.links())
    return response
1246945
def response(cls, dic, status=200):
        
        response = JsonResponse(dic, status=status)
        response['Cache-Control'] = 'no-store'
        response['Pragma'] = 'no-cache'

        return response
1119052
def returns_json(func):
    
    def decorator(*args, **kwargs):
        instance = args[0]
        request = getattr(instance, 'request', None)
        request.response.setHeader("Content-Type", "application/json")
        result = func(*args, **kwargs)
        return json.dumps(result)
    return decorator
1205690
def _process(self, resource=None, data={}):
        
        # use object's data if no data is passed
        _data = data or self._data
        rsc_url = self.get_rsc_endpoint(resource)
        if _data:
            req = requests.post(rsc_url, data=json.dumps(_data),
                                headers=self.headers)
        else:
            req = requests.get(rsc_url, params=_data,
                               headers=self.headers)
        if req.status_code == 200:
            self._response = json.loads(req.text)
            if int(self._response['response_code']) == 00:
                return (True, self._response)
            else:
                return (False, self._response['response_text'])
        else:
            return (500, "Request Failed")
1036369
def _as_json(self, response):
        
        # Assume ClientResponse has "body", and otherwise it's a requests.Response
        content = response.text() if hasattr(response, "body") else response.text
        try:
            return json.loads(content)
        except ValueError:
            raise DeserializationError(
                "Error occurred in deserializing the response body.")
1150273
def render_to_json(self, context, **response_kwargs):
        
        response_kwargs['content_type'] = 'application/json'
        return self.response_class(
            self.convert_context_to_json(context),
            **response_kwargs
        )
1123793
def build_response(description, resource=None):
    
    response = swagger.Response(
        description=description,
    )
    if resource is not None:
        response.schema = swagger.JsonReference({
            "$ref": "#/definitions/{}".format(type_name(name_for(resource))),
        })
    return response
128692
def to_swagger(self, bound_resource=None):
        
        response_def = _to_swagger(
            description=self.description,
            resource=bound_resource if self.resource is DefaultResource else self.resource,
        )
        status = self.status if self.status == 'default' else self.status.value
        return status, response_def
713992
def from_request(request=None) -> dict:
    

    request = request if request else flask_request

    try:
        json_args = request.get_json(silent=True)
    except Exception:
        json_args = None

    try:
        get_args = request.values
    except Exception:
        get_args = None

    arg_sources = list(filter(
        lambda arg: arg is not None,
        [json_args, get_args, {}]
    ))

    return arg_sources[0]
139254
def response(self, action=None):
        
        if action in self.cache:
            return utils.json_loads(self.cache[action]['response'])
        return self.cache.keys() or None
834522
def get_resources(self):
        
        status, _, body = self._request('GET', '/',
                                        {'Accept': 'application/json'})
        if status == 200:
            tmp, resources = json.loads(bytes_to_str(body)), {}
            for k in tmp:
                # The keys and values returned by json.loads() are unicode,
                # which will cause problems when passed into httplib later
                # (expecting bytes both in Python 2.x and 3.x).
                # We just encode the resource paths into bytes, with an
                # encoding consistent with what the resources module expects.
                resources[k] = tmp[k].encode('utf-8')
            return resources
        else:
            return {}
791068
def resource_response(resource, depth=0):
    
    if _get_acceptable_response_type() == JSON:
        depth = 0
        if 'expand' in request.args:
            depth = 1
        return _single_resource_json_response(resource, depth)
    else:
        return _single_resource_html_response(resource)
768188
def getFlaskResponse(responseString, httpStatus=200):
    
    return flask.Response(responseString, status=httpStatus, mimetype=MIMETYPE)
85628
def render_json_response(self, context, status=200):
        
        json_context = json.dumps(context, cls=self.json_encoder_class)

        return HttpResponse(json_context,
                            content_type=self.get_content_type(),
                            status=status)
1264298
def post(self, resource):
        
        response = self.api.execute(
            "POST", self.endpoint, json=(resource.as_dict()))

        if not response.ok:
            raise Error.parse(response.json())

        return self._cls.parse(response.json())
176036
def _make_response(sijax_response):
    """"""
    from types import GeneratorType

    if isinstance(sijax_response, GeneratorType):
        # Streaming response using a generator (non-JSON response).
        # Upon returning a response, Flask would automatically destroy
        # the request data and uploaded files - done by `flask.ctx.RequestContext.auto_pop()`
        # We can't allow that, since the user-provided callback we're executing
        # from within the generator may want to access request data/files.
        # That's why we'll tell Flask to preserve the context and we'll clean up ourselves.

        request.environ['flask._preserve_context'] = True

        # Clean-up code taken from `flask.testing.TestingClient`
        def clean_up_context():
            top = _request_ctx_stack.top
            if top is not None and top.preserved:
                top.pop()

        # As per the WSGI specification, `close()` would be called on iterator responses.
        # Let's wrap the iterator in another one, which will forward that `close()` call to our clean-up callback.
        response = Response(ClosingIterator(sijax_response, clean_up_context), direct_passthrough=True)
    else:
        # Non-streaming response - a single JSON string
        response = Response(sijax_response)

    return response
743334
def output(self, resource):
        
        @wraps(resource)
        def wrapper(*args, **kwargs):
            rv = resource(*args, **kwargs)
            rv = self.responder(rv)
            return rv

        return wrapper