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

add a json param in the callbacks and openapi docs #1095

Open
sansyrox opened this issue Dec 24, 2024 · 1 comment
Open

add a json param in the callbacks and openapi docs #1095

sansyrox opened this issue Dec 24, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@sansyrox
Copy link
Member

No description provided.

@sansyrox sansyrox added the enhancement New feature or request label Dec 24, 2024
@randomseed42
Copy link

randomseed42 commented Dec 24, 2024

Thanks for opening this issue, I'll just post my example here to explain the scenario:

  • only if you add body: Body in the route method, it will show Request body in /docs, otherwise you can not test your route in /docs
  • the body arg is not useful since it is already converted to json as request.json()
from robyn import Robyn, Request
from robyn.types import Body


app = Robyn(__file__)


@app.post('/api/c2f')
async def c2f(request: Request) -> dict | None:
    data = request.json()
    if 'celsius' not in data:
        return
    return {'fahrenheit': float(data['celsius']) * 9 / 5 + 32}


@app.post('/api/f2c')
async def f2c(request: Request, body: Body) -> dict | None:
    data = request.json()
    if 'fahrenheit' not in data:
        return
    return {'celsius': (float(data['fahrenheit']) - 32) * 5 / 9}


if __name__ == '__main__':
    app.start(host='127.0.0.1', port=8000)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants