Skip to content

Instantly share code, notes, and snippets.

@joevandyk
Created January 1, 2015 18:23
Show Gist options
  • Save joevandyk/6584c8deffe283573bd3 to your computer and use it in GitHub Desktop.
Save joevandyk/6584c8deffe283573bd3 to your computer and use it in GitHub Desktop.
### Create a table that has name and email, and create a view that versions the way to access the table.
tanga_dev=# create table foos (id serial primary key, name text, email text);
tanga_dev=# create view "1".foos as (select * from foos);
### That's all the code, now we can use http to get, read, update, and delete the data.
$ curl -d '{"name": "bob", "email": "[email protected]"}' http://localhost:3000/foos
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"[email protected]"}]
$ curl -d '{"name": "joe", "email": "[email protected]"}' http://localhost:3000/foos
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"[email protected]"},{"id":4,"name":"joe","email":"[email protected]"}]
$ curl -X PATCH -d '{"email": "[email protected]"}' http://localhost:3000/foos?id=eq.4
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"[email protected]"},{"id":4,"name":"joe","email":"[email protected]"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment