8000 PUT on the browsable API renderer actually performs POST · Issue #138 · flask-api/flask-api · GitHub
[go: up one dir, main page]

Skip to content

PUT on the browsable API renderer actually performs POST #138

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

Open
andreareina opened this issue Sep 11, 2021 · 7 comments
Open

PUT on the browsable API renderer actually performs POST #138

andreareina opened this issue Sep 11, 2021 · 7 comments

Comments

@andreareina
Copy link

Given a route that accepts PUT and GET but not POST, the browsable API renderer performs a POST despite the button very clearly showing PUT.

image
image

from flask_api import FlaskAPI

app = FlaskAPI(__name__)

@app.route("/", methods=["PUT", "GET"])
def index():
    return {}

if __name__ == "__main__":
    app.run(debug=True)

requirements.txt

@auvipy
Copy link
Collaborator
auvipy commented Sep 11, 2021

ops

@papiveron
Copy link
papiveron commented Nov 1, 2021

I've got the same issue and treated browser POST method as PUT in my API code.

But the same behaviour appears with DELETE.
The browsable API renderer performs a POST despite the button very clearly showing DELETE.

I'dont if it's the UI which maps DELETE button method on POST method, or if it's at the browser side.

I'm still looking for how to identify and solve the issue.

Eugène NG

@papiveron
Copy link

I edited the library code and move the form method there from POST to DELETE thinking it could solve the problem this way :

Screenshot 2021-11-01 at 20 31 52

104         {% if 'DELETE' in allowed_methods %}
105             <form class="button-form" action="{{ request.url }}" method="DELETE" class="pull-right">
106                 <!-- csrf_token -->
107                 <input type="hidden" name="_method" value="DELETE" />
108                 <button class="btn btn-danger js-tooltip" title="Make a DELETE request on the resource">DELETE</button>
109             </form>
110         {% endif %}

But not, the browser is now sending a GET request with the query string _method=DELETE, instead of DELETE request/method.

flask-api-delete-request-debugging

Still checking

@papiveron
Copy link

I searched and figured out that it's just because we can't sent DELETE or PUT request in a HTML form.

So the good thing will be to replace this html code block with javascript jquery/ajax code :

104         {% if 'DELETE' in allowed_methods %}
105             <form class="button-form" action="$delte"  method="POST" class="pull-right">
106                 <!-- csrf_token -->
107                 <input type="hidden" name="_method" value="DELETE" />
108                 <button class="btn btn-danger js-tooltip" title="Make a DELETE request on the resource">DELETE</button>
109             </form>
110         {% endif %}

How to achieve that please?

@papiveron
Copy link

I abandoned the effort of making the browser sending DELETE requests, and dealed with form hiden inputs, keeping POST as the form's method

104         {% if 'DELETE' in allowed_methods %}
105             <form class="button-form" action="{{ request.url }}" method="POST" class="pull-right">
106                 <!-- csrf_token -->
107                 <input type="hidden" name="_method" value="DELETE" />
108                 <button class="btn btn-danger js-tooltip" title="Make a DELETE request on the resource">DELETE</button>
109             </form>
110         {% endif %}

We can do the same thing for PUT

Forme the issue should be closed we identified the problem and have workarounds

@Nadav-Ruskin
Copy link

This is still a problem.

@auvipy
Copy link
Collaborator
auvipy commented Jul 6, 2022

a fix need to be applied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0