# Not been able to add POST api method using Flask

**URL:** <https://discuss.huggingface.co/t/not-been-able-to-add-post-api-method-using-flask/158508>\
**Category:** Beginners\
**Created:** [June 8, 2025, 9:49pm UTC](https://discuss.huggingface.co/t/not-been-able-to-add-post-api-method-using-flask/158508 "2025-06-08T21:49:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajender0010](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rajender0010](https://discuss.huggingface.co/u/rajender0010)\
**Post date:** [June 8, 2025, 9:49pm UTC](https://discuss.huggingface.co/t/not-been-able-to-add-post-api-method-using-flask/158508/1 "2025-06-08T21:49:24Z")

</div>

Hi,  
Below is the POST method I added:  
@app.route(‘/greet’, methods=[‘POST’])  
def greet():  
“”"  
Handles POST requests to the /greet endpoint.  
Expects JSON data with a ‘name’ field.  
“”"  
data = request.get\_json()  
if data and ‘name’ in data:  
name = data[‘name’]  
return jsonify({“message”: f"Hello, {name}!"}), 200  
else:  
return jsonify({“error”: “Invalid request. Please provide ‘name’ in JSON data.”}), 400

Getting the error code 404 and text response as ‘Cannot POST /spaces/name/space/v1/greet’

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [June 9, 2025, 2:41am UTC](https://discuss.huggingface.co/t/not-been-able-to-add-post-api-method-using-flask/158508/2 "2025-06-09T02:41:46Z")

</div>

Hmm… Like this issue?

> [@FastAPI Routing Issue in Hugging Face Spaces](https://discuss.huggingface.co/t/fastapi-routing-issue-in-hugging-face-spaces/54962):
>
> Hello everyone, I’ve deployed a FastAPI application on Hugging Face Spaces. Everything seems to be running smoothly, and there are no errors in the logs. However, when I try to access my endpoints via a browser or tools like Postman, I’m getting a “404 error” or a “Cannot POST” error. Here’s a brief overview of my setup: I have a FastAPI route defined as @app.get("/check\_request") and another one as @app.post("/recommend"). My Dockerfile specifies the CMD as CMD ["uvicorn", "app:app", "--hos…

---

<div class="post-metadata">

**Author:** ![Mdrnfox](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mdrnfox/32/47695_2.png) [@Mdrnfox](https://discuss.huggingface.co/u/Mdrnfox)\
**Post date:** [June 9, 2025, 5:58pm UTC](https://discuss.huggingface.co/t/not-been-able-to-add-post-api-method-using-flask/158508/3 "2025-06-09T17:58:54Z")

</div>

> [@rajender0010](#):
>
> def greet():  
> “”"  
> Handles POST requests to the /greet endpoint.  
> Expects JSON data with a ‘name’ field.  
> “”"  
> data = request.get\_json()  
> if data and ‘name’ in data:  
> name = data[‘name’]  
> return jsonify({“message”: f"Hello, {name}!"}), 200  
> else:  
> return jsonify({“error”: “Invalid request. Please provide ‘name’ in JSON data.”}), 400
> 
> Getting the error code 404 and text response as ‘Cannot POST /spaces/name/space/v1/greet’

Throw this in there to help you debug a bit better.  
if data and ‘name’ in data:  
name = data[‘name’]  
return jsonify({“message”: f"Hello, {name}!"}), 200  
else:  
return jsonify({“error”: “Invalid request. Please provide ‘name’ in JSON data.”}), 400

The frontend or client is POSTing to a different path or the data is in a bad format and you aren’t grabbing name.

Try a curl on the api to test it as well.
