Skip to content

Conversation

@arybhatt4533
Copy link

Description

Added get_url method to ProductResource and exposed product_update_url.

Solution

The goal of this PR is to allow users to inspect the API URLs without actually triggering a network request. Here’s how I handled it:

Extracted URL Logic: I created a new get_url method. Previously, the URL construction was hardcoded inside the get method. Now, it lives in its own reusable function.

Refactored get method: I updated the existing get method to call get_url internally. This removes code duplication and keeps the logic consistent.
image

Exposed Update URL: I added a product_update_url property. This gives users a direct way to see the endpoint used for product updates (/cgi/product_jqm2.pl).

Improved Flexibility: Users can now pass a list of fields to get_url to see exactly what the final query string will look like before fetching data.
image

Related issue(s)

  • Fixes #[391]

@sonarqubecloud
Copy link

# See
# https://github.com/openfoodfacts/openfoodfacts-server/issues/1607
url += "?fields={}".format(",".join(fields))
url = self.get_url(code, fields)
Copy link
Member

Choose a reason for hiding this comment

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

you don’t need a separate function. can the logic go directly inside the existing get() method? 🤔

Copy link
Author

@arybhatt4533 arybhatt4533 Dec 20, 2025

Choose a reason for hiding this comment

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

The URL construction was extracted into get_url() so it can be reused and inspected independently of get().
This allows users to log or debug the exact endpoint without triggering a request, which aligns with the original goal of exposing the URL.
If you prefer keeping the logic inline for simplicity, I can move it back into get().
@areebahmeddd

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants