-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Expected Behavior
A GET request to queue/item/get should accept parameters based on an item uid or position, and return the corresponding plan.
Current Behavior
Parameters are not accepted by the fastAPI endpoint, instead it accepts a body (payload: dict {}) which can then include key value pairs for 'uid' or 'pos'. The issue with this method is that client side libraries for HTTP requests generally do not allow a body to be included in GET requests. GET requests typically include request parameters when needed.
@router.get("/queue/item/get")
async def queue_item_get_handler(
payload: dict = {}, principal=Security(get_current_principal, scopes=["read:queue"])
):
"""
Get a plan from the queue
"""
try:
msg = await SR.RM.item_get(**payload)
except Exception:
process_exception()
return msg
Possible Solution
Modify the endpoint to accept request parameters for the uid and position.
@router.get("/queue/item/get")
async def queue_item_get_handler(
uid: Optional[str] = None,
pos: Optional[int] = None,
principal=Security(get_current_principal, scopes=["read:queue"])
):
"""
Get a plan from the queue via the uid or current position. Returns the highest index plan if no parameters are provided. Returns the item by uid if both uid and position parameters are provided.
"""
try:
if uid is not None:
msg = await SR.RM.item_get(uid=uid)
elif pos is not None:
msg = await SR.RM.item_get(pos=pos)
else:
msg = await SR.RM.item_get() #return most recent item by default
except Exception:
process_exception()
return msg
Context
When using this endpoint from a client web app (Javascript), http request libraries like axios or even the built in fetch library are not able to include a body in GET requests, therefore the client is unable to correctly use the endpoint to retrieve information on specific plans.
Your Environment
Python 3.10.13