Update the functions documentation for python lib (#18623)

* Update the functions documentation for python lib

* Apply suggestions from code review

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>

---------

Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>
This commit is contained in:
Andrew SmithandCopple authored and GitHub committed 2023-10-31 19:43:35 +00:00
1 parent 0958c14f9e
commit 6af4035448
1 file changed
+51 -8
+51 -8
View File
@@ -1795,16 +1795,59 @@ functions:
name: Basic invocation
description:
code: |
```python
resp = supabase.functions.invoke(
"hello-world",
invoke_options={
"body": { "foo": "bar" }
},
)
```
func = supabase.functions()
@asyncio.coroutine
async def test_func(loop):
resp = await func.invoke("hello-world",invoke_options={'body':{}})
return resp
- id: error-handling
name: Error handling
description: |
Returns one of the following errors:
- `FunctionsHttpError`: if your function throws an error
- `FunctionsRelayError`: if the Supabase Relay encounters an error processing your function
isSpotlight: true
code: |
```python
from supafunc.errors import FunctionsRelayError, FunctionsHttpError
loop = asyncio.get_event_loop()
resp = loop.run_until_complete(test_func(loop))
loop.close()
try:
resp = supabase.functions.invoke(
"hello-world",
invoke_options={
"body": {"foo": "bar"},
"headers": {"my-custom-header": "my-custom-header-value"},
},
)
except FunctionsHttpError as exception:
err = exception.to_dict()
print(f"Function returned an error {err.get("message")}")
except FunctionsRelayError as exception:
err = exception.to_dict()
print(f"Relay error: {err.get("message")}")
```
- id: passing-custom-headers
name: Passing custom headers
description: |
The library accepts custom headers via the `headers` option.
Note: `supabase-py` automatically populates the `Authorization` header if there is a signed in user.
isSpotlight: true
code: |
```python
resp = supabase.functions.invoke(
"hello-world",
invoke_options={
"headers": {
"my-custom-header": "my-custom-header-value"
},
"body": { "foo": "bar" }
}
)
```
- id: list-buckets