Skip to content

feat: add DestinationHttpClient to simplify calls to target systems#119

Open
jplbrun wants to merge 3 commits into
mainfrom
feat/special-header-providers
Open

feat: add DestinationHttpClient to simplify calls to target systems#119
jplbrun wants to merge 3 commits into
mainfrom
feat/special-header-providers

Conversation

@jplbrun
Copy link
Copy Markdown
Contributor

@jplbrun jplbrun commented May 13, 2026

Description

Adds DestinationHttpClient, a requests wrapper that makes calling a target system from a destination straightforward. Previously, users had to manually fetch an auth token from destination properties and build the Authorization header themselves, and also manually set the sap-client header for OnPremise destinations. With this change:

dest = client.get_destination("my-destination")
http = DestinationHttpClient(dest)
response = http.get("/api/resource")

The client pre-bakes auth headers from dest.auth_tokens (populated by the v2 API) and SAP ERP headers (sap-client, sap-language) into the session at construction time.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

  1. Get a destination using the v2 API: dest = client.get_destination("my-destination")
  2. Instantiate the client: http = DestinationHttpClient(dest)
  3. Call the target system: response = http.get("/api/resource")
  4. Verify that headers are sent automatically without manual setup
  5. Run unit tests: uv run pytest tests/destination/unit/test_destination_http_client.py -v

Related Issue

Closes #35

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

@jplbrun jplbrun marked this pull request as ready for review May 13, 2026 16:49
@jplbrun jplbrun requested a review from a team as a code owner May 13, 2026 16:49


class DestinationHttpClient:
"""Wraps requests.Session to call the target system described by a Destination.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary for us to wrap the requests.Session object? I mean we are wrapping all the methods from requests.Session (get, put, post, delete and request) without doing anything extra.

Maybe we could just offer a factory for developers to create a Session object populated with the necessary headers from the destination.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we don't need to return Session, but we could expose a single method of request allowing selection of path and HttpMethod

Comment on lines +38 to +43
# Pre-bake auth headers — BTP may return multiple tokens, skip empty ones
for token in destination.auth_tokens:
key = token.http_header.get("key")
value = token.http_header.get("value")
if key and value:
self._session.headers[key] = value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about token refreshing?

@NicoleMGomes
Copy link
Copy Markdown
Contributor

Update user-guide

self._session = requests.Session()

# Pre-bake sap-client / sap-language — relevant mainly for OnPremise destinations
self._session.headers.update(destination.get_erp_headers())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All headers from destination should be used, not only token and erp. Is this the case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide Special Header Providers from Java SDK for OnPremise Destinations

3 participants