I’m a novice in Api development and I have been following this tutorial YouTube and I am currently stock at performing the delete operation, using FastApi and SQL alchemy. I am using postman to test my Apis and each time I send a delete request it sends back a 405 error. I searched through my code but can’t seem to figure out what the problem is can anyone help me out. Here is sample of the code.
@app.delete("posts/{id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_posts(id: int,db: Session=Depends(get_db)):
#cur.execute("DELETE FROM posts WHERE id=%s RETURNING * ", (str(id),))
#deleted_post = cur.fetchone()
#conn.commit()
post = db.query(models.Post).filter(models.Post.id==id)
if post.first() == None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"post with {id} not found!")
post.delete(synchronize_session=False)
db.commit()
return Response(status_code=status.HTTP_204_NO_CONTENT)
here is the response from my command line interface
here is the response from my postman
I searched through the code and coudln’t find the bug.
James is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.