You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How do I (is there a way to) transform a method argument into a query parameter?
#340
I have an API where I need to pass in a query param that looks like /config?childconditions=company%2Fid%3D73. That last bit is the urlencoded equivalent of company/id=73 where 73 is of course an integer company id that comes from another endpoint. Is there a way to just pass in 73 to my uplink method when some code is calling it, but then have it transform it correctly for insertion into the params for the API call it's about to make?
What I have in my code right now, which works just fine but is going to get very boilerplate-y very quickly because I need to do this for all my functions:
@uplink.get('config')def_get_configurations(self, conditions: uplink.Query):
"""Get configurations for a specific company."""defget_configurations(self, company_id: int):
"""Get configurations for a specific company."""returnself._get_configurations(conditions=f'company/id={company_id}')
What I'd prefer to be able to write:
@uplink.params({'conditions': 'company/id={company_id}'})@uplink.get('config')defget_configurations(self, company_id: uplink.Query):
"""Get configurations for a specific company."""
When I tried this last block of code, it generated a request url of /config?company_id=73&conditions=company%2Fid%3D%7Bcompany_id%7D
The company_id that is passed in to this method should not be inserted as-is in the query params, but should only be inserted after being transformed and interpolated into the actual query param I want to insert.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I have an API where I need to pass in a query param that looks like
/config?childconditions=company%2Fid%3D73. That last bit is the urlencoded equivalent ofcompany/id=73where 73 is of course an integer company id that comes from another endpoint. Is there a way to just pass in 73 to my uplink method when some code is calling it, but then have it transform it correctly for insertion into the params for the API call it's about to make?What I have in my code right now, which works just fine but is going to get very boilerplate-y very quickly because I need to do this for all my functions:
What I'd prefer to be able to write:
When I tried this last block of code, it generated a request url of
/config?company_id=73&conditions=company%2Fid%3D%7Bcompany_id%7DThe company_id that is passed in to this method should not be inserted as-is in the query params, but should only be inserted after being transformed and interpolated into the actual query param I want to insert.
All reactions