Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

Update doc for Dynamic Routes

Open paroxyste-0 opened this issue 1 year ago • 0 comments

Hello, I am currently testing the framework on version 0.37, and I have noticed an issue with accessing the path parameter.

The documentation mentions the following code:

from robyn import jsonify

@app.post("/jsonify/:id")
async def json(request):

    print(request["path_params"]["id"])

    return jsonify({"hello": "world"})

However, when executing this example, the following error occurs:

TypeError: 'builtins.Request' object is subscriptable

To make it work, you should correct the example as follows:

@app.post("/jsonify/:id")
async def json(request):
    # First example
    id = request.path_params["id"]

    # Or
    id = request.path_params.get('id')

    return jsonify({"hello": "world"})

Thanks

paroxyste-0 avatar Sep 14 '23 12:09 paroxyste-0