mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +03:00
add in generated files
This commit is contained in:
1 parent
cbf2df6845
commit
822f26c982
3 files changed
+29
-28
No files matched your search
@@ -12,7 +12,7 @@ Invokes a Supabase Function.
|
||||
|
||||
```js
|
||||
const { data: user, error } = await supabase.functions.invoke('hello', {
|
||||
body: JSON.stringify({ foo: 'bar' }),
|
||||
body: { foo: 'bar' },
|
||||
})
|
||||
```
|
||||
|
||||
@@ -115,26 +115,46 @@ object representing the headers to send with the request
|
||||
|
||||
- Requires an Authorization header.
|
||||
- Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as application/json. You can override this behaviour by passing in a Content-Type header of your own.
|
||||
- Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic invocation.
|
||||
|
||||
null
|
||||
|
||||
```js
|
||||
const { data: user, error } = await supabase.functions.invoke('hello', {
|
||||
body: JSON.stringify({ foo: 'bar' }),
|
||||
body: { foo: 'bar' },
|
||||
})
|
||||
```
|
||||
|
||||
### Specifying response type.
|
||||
### Error handling.
|
||||
|
||||
By default, `invoke()` will parse the response as JSON. You can parse the response in the following formats: `json`, `blob`, `text`, and `arrayBuffer`.
|
||||
A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.
|
||||
|
||||
```js
|
||||
import {
|
||||
FunctionsHttpError,
|
||||
FunctionsRelayError,
|
||||
FunctionsFetchError,
|
||||
} from '@supabase/supabase-js'
|
||||
|
||||
const { data: user, error } = await supabase.functions.invoke('hello', {
|
||||
responseType: 'text',
|
||||
body: JSON.stringify({ foo: 'bar' }),
|
||||
headers: {
|
||||
'my-custom-header': 'my-custom-header-value',
|
||||
},
|
||||
body: { foo: 'bar' },
|
||||
})
|
||||
|
||||
if (error instanceof FunctionsHttpError) {
|
||||
console.log('Function returned an error', error.message)
|
||||
} else if (error instanceof FunctionsRelayError) {
|
||||
console.log('Relay error:', error.message)
|
||||
} else if (error instanceof FunctionsFetchError) {
|
||||
console.log('Fetch error:', error.message)
|
||||
}
|
||||
```
|
||||
|
||||
### Passing custom headers.
|
||||
@@ -146,6 +166,6 @@ const { data: user, error } = await supabase.functions.invoke('hello', {
|
||||
headers: {
|
||||
'my-custom-header': 'my-custom-header-value',
|
||||
},
|
||||
body: JSON.stringify({ foo: 'bar' }),
|
||||
body: { foo: 'bar' },
|
||||
})
|
||||
```
|
||||
@@ -139,7 +139,7 @@ const { data, error } = await supabase
|
||||
.from('users')
|
||||
.update(
|
||||
`
|
||||
address: {
|
||||
address: {
|
||||
street: 'Melrose Place',
|
||||
postcode: 90210
|
||||
}
|
||||
|
||||
@@ -760,7 +760,7 @@ pages:
|
||||
notes: |
|
||||
- Requires an Authorization header.
|
||||
- Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as application/json. You can override this behaviour by passing in a Content-Type header of your own.
|
||||
- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own.
|
||||
- Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
|
||||
examples:
|
||||
- name: Basic invocation.
|
||||
@@ -982,25 +982,6 @@ pages:
|
||||
{ name: 'Rohan', country_id: 555 },
|
||||
])
|
||||
```
|
||||
- name: Upsert
|
||||
description: |
|
||||
For upsert, if set to true, primary key columns would need to be included
|
||||
in the data parameter in order for an update to properly happen. Also, primary keys
|
||||
used must be natural, not surrogate. There are however,
|
||||
[workarounds](https://github.com/PostgREST/postgrest/issues/1118)
|
||||
for surrogate primary keys.
|
||||
js: |
|
||||
```js
|
||||
const { data, error } = await supabase
|
||||
.from('cities')
|
||||
.insert(
|
||||
[
|
||||
{ name: 'The Shire', country_id: 554 },
|
||||
{ name: 'Rohan', country_id: 555 },
|
||||
{ name: 'City by the Bay', country_id:840}
|
||||
],
|
||||
{ upsert: true })
|
||||
```
|
||||
|
||||
update():
|
||||
title: 'Modify data: update()'
|
||||
|
||||
Reference in new issue
Block a user