How should I format a JSON POST request to my rails app?

First of all, I think your data format is ok and is not the problem here. When I ran exactly into the same problem it was because I did not send the Content-Type: application/json header along with my request.

In Postman, you can select the ‘raw’ data format and then ‘JSON (application/json)’ to include this header. In my case it looks like this:

Screenshot of sending a JSON request to a rails application in Postman

Alternatively, you can also try it with curl (source):

curl -X POST -H "Content-Type: application/json" -d '{"player": {"name": "test","room_id": 0,"skin_id": 1,"head_id": 2,"torso_id": 3,"legs_id": 4,"x_position": 5,"y_position": 6,"direction": 7,"action": "","gender": "f"}}' localhost:3000/players.json

If you omit the -H "Content-Type: application/json", then you will receive a 400 response with the “param not found” error, if you include it it should work.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)