Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify queue/item/get endpoint to accept request parameters instead of body #64

Open
SeijDeLeon opened this issue Jul 24, 2024 · 2 comments

Comments

@SeijDeLeon
Copy link

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

@AnnaShazk
Copy link

AnnaShazk commented Oct 11, 2024

I also get the same issue with endpoints for Console Output of RE Manager:
https://blueskyproject.io/bluesky-httpserver/control_re_manager.html#console-output-of-re-manager

@router.get("/console_output_update")
def console_output_update(payload: dict, principal=Security(get_current_principal, scopes=["read:console"])):
    """
    Download the list of new messages that were accumulated at the server. The API
    accepts a required parameter ``last_msg_uid`` with UID of the last downloaded message.
    If the UID is not found in the buffer, an empty message list and valid UID is
    returned. If UID is ``"ALL"``, then all accumulated messages in the buffer is
    returned. If UID is found in the buffer, then the list of new messages is returned.

    At the client: initialize the system by sending request with ``last_msg_uid`` set
    to random string or ``"ALL"``. In each request use ``last_msg_uid`` returned by the previous
    request to download new messages.
    """
    try:
        validate_payload_keys(payload, required_keys=["last_msg_uid"])

        response = SR.console_output_loader.get_new_msgs(last_msg_uid=payload["last_msg_uid"])
        # Add 'success' and 'msg' so that the API is compatible with other QServer API.
        response.update({"success": True, "msg": ""})
    except Exception:
        process_exception()

    return response
@router.get("/console_output")
async def console_output(payload: dict = {}, principal=Security(get_current_principal, scopes=["read:console"])):
    try:
        n_lines = payload.get("nlines", 200)
        text = await SR.console_output_loader.get_text_buffer(n_lines)
    except Exception:
        process_exception()

    # Add 'success' and 'msg' so that the API is compatible with other QServer API.
    return {"success": True, "msg": "", "text": text}

@AnnaShazk
Copy link

also there another problem with console_output endpoint, after some amount of lines in console its stopped update , so we get outdate data at some point

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

No branches or pull requests

2 participants