以下在Ubuntu环境运行

安装postgresql

sudo apt install postgresql
sudo apt install libpq-dev

安装postgREST

(最新下载地址)

mkdir postgrest
cd postgrest
wget https://github.com/PostgREST/postgrest/releases/download/v5.1.0/postgrest-v5.1.0-ubuntu.tar.xz
tar xfJ postgrest-v5.1.0-ubuntu.tar.xz

切换到Ubuntu的postgres用户,进入psql的postgres用户

sudo su - postgres    
psql -U postgres

命令提示符变为

psql (9.6.3)
Type "help" for help.

postgres=#

并创建postgREST环境

create schema api;
create table api.todos (
  id serial primary key,
  done boolean not null default false,
  task text not null,
  due timestamptz
);

insert into api.todos (task) values
  ('finish tutorial 0'), ('pat self on back');
create role web_anon nologin;
grant web_anon to postgres;

grant usage on schema api to web_anon;
grant select on api.todos to web_anon;

修改一个密码

\password postgres

退出psql和postgres用户

\q
exit

创建postgREST配置文件

db-uri = "postgres://postgres:mysecretpassword@localhost/postgres"
db-schema = "api"
db-anon-role = "web_anon"

运行postgREST

./postgrest tutorial.conf

本机上已经搞定了!现在可以尝试发起RESTful请求了。本机上:

curl http://localhost:3000/todos

标签: none 阅读量: 1346

添加新评论