Skip to content

How to access the response headers? #171

@luzfcb

Description

@luzfcb

Hi, I'm maintaining an existing application from a customer and there is an API client implementation of an external service that is implemented using tapioca-wrapper (v1.4.2). The external service now includes some headers in the response of each request and I need to perform different actions depending on the value that specific headers have.

Is there an official way to access the raw response object (not only the response body) from the TapiocaClient or TapiocaClientExecutor?

From the example below, how to access the response HEADERS from the tapioca_client instance, tapioca_client_executor instance, or from the result object of the get() method call?

from tapioca import TapiocaAdapter, generate_wrapper_from_adapter, JSONAdapterMixin
from requests.auth import HTTPBasicAuth

from .mapping import RESOURCE_MAPPING


class FooBarClientAdapter(JSONAdapterMixin, TapiocaAdapter):
    api_root = 'https://api.foobar.com/'
    resource_mapping = RESOURCE_MAPPING


FooBarClientClass = generate_wrapper_from_adapter(FooBarClientAdapter)

tapioca_client = FooBarClientClass()

url = "https://api.foobar.com/resource/123/?x=1&y=2"

tapioca_client_executor = tapioca_client._wrap_in_tapioca_executor(url)

page = 1

data = tapioca_client_executor.get(params={'page': page})

# The .response raises an exception
# tapioca_client_executor.response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions