Why fastapi trace http method not working?

Question:

that’s my code idk what should i put in view

TypeError: Failed to execute ‘fetch’ on ‘Window’: ‘TRACE’ HTTP method is unsupported.

from fastapi import FastAPI

app = FastAPI()

@app.trace("/")
def test_trace():
    ...

enter image description here

Asked By: amirbahador

||

Answers:

That’s not a problem with your code but the browser. The TRACE HTTP method has little to no support on browsers according to MDN. And since the swagger UI page for FastAPI uses the browser to make these API calls, it may not work.

However your code is working as expected. You can check that by using curl:

(venv) ➜ curl -X TRACE http://127.0.0.1:8000
"test"%                                                                                                                                                                     (venv) ➜ 

From the handler method:

@app.trace("/")
def test_trace():
    return "test"
Answered By: rdas
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.