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

Refactor ctx.body #8

Open
noraa-july-stoke opened this issue May 5, 2023 · 2 comments
Open

Refactor ctx.body #8

noraa-july-stoke opened this issue May 5, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@noraa-july-stoke
Copy link
Owner

noraa-july-stoke commented May 5, 2023

calling setter for ctx.body should include the json.dumps so that user doesn't have to call it in the route like this:

    print(ctx.auth, "ctx.auth")
    if ctx.auth and ctx.auth.get('user'):
        ctx.body = json.dumps({"message": "This is protected content. Only authenticated users can see this. I hope you feel special 🍊🍊🍊."})
        ctx.send(200, content_type='application/json')
    else:
        ctx.body = json.dumps({"message": "Unauthorized"})
        ctx.send(401, content_type='application/json')
        ```
@noraa-july-stoke noraa-july-stoke added enhancement New feature or request good first issue Good for newcomers labels May 5, 2023
@yechielb2000
Copy link

You can use https://pypi.org/project/http-constants/ for the http headers

@noraa-july-stoke
Copy link
Owner Author

@yechielb2000 that won't actually jsonify the response 🙃

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

No branches or pull requests

2 participants