如何将带有 curl 的 JSON 正文发送到 Postgrest

问题描述

我试图在我的 Postgresql 数据库上插入数据,但我失败了。

所以基本上我可以通过下面的查询选择数据;

curl 10.127.18.18:3001/mytable

我可以通过此请求获取所有行。

我尝试了很多以下命令的组合,但都失败了。如何使用 postgREST 插入基本数据?

mytable”表有 2 列,“user_id”和“用户名”;

curl POST 10.127.18.18:3001/mytable { "user_id": 3333,"username": testuser }
curl -X POST 10.127.18.18:3001/mytable HTTP/1.1 { "user_id": "3333","username": "testuser" }

谢谢!

解决方法

对于那些遇到同样问题的人,这个查询对我有用;

curl --location --request POST '10.127.18.18:3001/mytable' --header 'Content-Type: application/json' --data-raw '{  "user_id": "11","username": "test"  }'