Skip to content

Commit

Permalink
Merge pull request #35 from supabase/release_docs
Browse files Browse the repository at this point in the history
sync docs with sql
  • Loading branch information
olirice authored Jul 30, 2021
2 parents f909f31 + d3c1cd6 commit 3d52e77
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@

---

A PostgreSQL extension providing an async networking interface accessible via SQL using a [background worker](https://www.postgresql.org/docs/current/bgworker.html) and curl.
pg_net is a PostgreSQL extension exposing a SQL interface for async networking with a focus on scalability and UX.

Features:

- async http GET requests
- async http POST requests with a JSON payload
51 changes: 42 additions & 9 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ net.http_get(
-- url for the request
url text,
-- key/value pairs to be url encoded and appended to the `url`
params jsonb DEFAULT '{}'::jsonb,
params jsonb default '{}'::jsonb,
-- key/values to be included in request headers
headers jsonb DEFAULT '{}'::jsonb,
headers jsonb default '{}'::jsonb,
-- the maximum number of milliseconds the request may take before being cancelled
timeout_milliseconds int DEFAULT 1000
timeout_milliseconds int default 1000
)
-- request_id reference
returns bigint
Expand Down Expand Up @@ -63,7 +63,7 @@ net.http_post(
-- key/values to be included in request headers
headers jsonb default '{"Content-Type": "application/json"}'::jsonb,
-- the maximum number of milliseconds the request may take before being cancelled
timeout_milliseconds int DEFAULT 1000
timeout_milliseconds int default 1000
)
-- request_id reference
returns bigint
Expand All @@ -78,8 +78,8 @@ net.http_post(
select
net.http_post(
url:='https://httpbin.org/post',
body:='{"hello": "world"}'::jsonb,
);
body:='{"hello": "world"}'::jsonb
) as request_id;
request_id
----------
1
Expand All @@ -101,7 +101,7 @@ When `async:=false` is set it is recommended that [statement_timeout](https://ww
```sql
net.http_collect_response(
-- request_id reference
request_id id,
request_id bigint,
-- when `true`, return immediately. when `false` wait for the request to complete before returning
async bool default true
)
Expand All @@ -115,7 +115,11 @@ net.http_collect_response(

##### usage
```sql
select net.http_get('https://news.ycombinator.com') as request_id;
select
net.http_post(
url:='https://httpbin.org/post',
body:='{"hello": "world"}'::jsonb
) as request_id;
request_id
----------
1
Expand All @@ -125,12 +129,41 @@ select * from net.http_collect_response(1, async:=false);
status | message | response
--------+---------+----------
SUCCESS ok ...


select
(response).body::json
from
net.http_collect_response(request_id:=1);
body
-------------------------------------------------------------------
{
"args": {},
"data": "{\"hello\": \"world\"}",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Length": "18",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "pg_net/0.1",
"X-Amzn-Trace-Id": "Root=1-61031a5c-7e1afeae69bffa8614d8e48e"
},
"json": {
"hello": "world"
},
"origin": "135.63.38.488",
"url": "https://httpbin.org/post"
}
(1 row)
```

where `response` is a composite

```sql
status_code integer
headers jsonb
body text
```

Possible values for `net.http_response_result.status` are `('PENDING', 'SUCCESS', 'ERROR')`
6 changes: 3 additions & 3 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pg_netis OSS. PR and issues are welcome.
pg_net is OSS. PR and issues are welcome.


## Development
Expand All @@ -14,10 +14,10 @@ For testing locally, execute:
$ nix-shell

# test on pg 12
$ net-with-pg-12 make installcheck
$ net-with-pg-12 python -m pytest -vv"
# test on pg 13
$ net-with-pg-13 make installcheck
$ net-with-pg-13 python -m pytest -vv"
```

### Documentation
Expand Down
7 changes: 6 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@

---

A PostgreSQL extension providing an async networking interface accessible via SQL using a [background worker](https://www.postgresql.org/docs/current/bgworker.html) and curl.
pg_net is a PostgreSQL extension exposing a SQL interface for async networking with a focus on scalability and UX.

Features:

- async http GET requests
- async http POST requests with a JSON payload
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Tested to work on PostgreSQL 12 and 13.
Tested with PostgreSQL 12 and 13.

## Setup

Expand Down

0 comments on commit 3d52e77

Please sign in to comment.