diff --git a/src/content/doc-surrealql/functions/database/http.mdx b/src/content/doc-surrealql/functions/database/http.mdx index 3c1f36eda..a1d274608 100644 --- a/src/content/doc-surrealql/functions/database/http.mdx +++ b/src/content/doc-surrealql/functions/database/http.mdx @@ -134,7 +134,7 @@ The `http::put` function performs a remote HTTP `PUT` request. The first paramet ```surql title="API DEFINITION" http::put(string, object) -> value ``` -If an object is given as the second argument, then this can be used to set the request headers. +If an object is given as the third argument, then this can be used to set the request headers. ```surql title="API DEFINITION" http::put(string, object, object) -> value @@ -142,7 +142,7 @@ http::put(string, object, object) -> value The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealql/statements/return) statement: -```surql +```surql title="Request without headers" RETURN http::put('https://dummyjson.com/comments', { "id": 1, "body": "This is some awesome thinking!", @@ -152,8 +152,25 @@ RETURN http::put('https://dummyjson.com/comments', { "username": "eburras1q" } }); +``` +```surql title="Request with headers" +RETURN http::put('https://dummyjson.com/comments', { + "id": 1, + "body": "This is some awesome thinking!", + "postId": 100, + "user": { + "id": 63, + "username": "eburras1q" + } +}, { + 'Authorization': 'Bearer your-token-here', + 'Content-Type': 'application/json', + 'x-custom-header': 'custom-value' +}); +``` +```surql title="Response" { "id": 1, "body": "This is some awesome thinking!", @@ -174,7 +191,7 @@ The `http::post` function performs a remote HTTP `POST` request. The first param ```surql title="API DEFINITION" http::post(string, object) -> value ``` -If an object is given as the second argument, then this can be used to set the request headers. +If an object is given as the third argument, then this can be used to set the request headers. ```surql title="API DEFINITION" http::post(string, object, object) -> value @@ -182,7 +199,7 @@ http::post(string, object, object) -> value The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealql/statements/return) statement: -```surql +```surql title="Request without headers" RETURN http::post('https://dummyjson.com/comments/1', { "id": 1, "body": "This is some awesome thinking!", @@ -192,8 +209,25 @@ RETURN http::post('https://dummyjson.com/comments/1', { "username": "eburras1q" } }); +``` +```surql title="Request with headers" +RETURN http::post('https://dummyjson.com/comments/1', { + "id": 1, + "body": "This is some awesome thinking!", + "postId": 100, + "user": { + "id": 63, + "username": "eburras1q" + } +}, { + 'Authorization': 'Bearer your-token-here', + 'Content-Type': 'application/json', + 'x-custom-header': 'custom-value' +}); +``` +```surql title="Response" { "id": 1, "body": "This is some awesome thinking!", @@ -222,7 +256,7 @@ http::patch(string, object, object) -> value The following example shows this function, and its output, when used in a [`RETURN`](/docs/surrealql/statements/return) statement: -```surql +```surql title="Request without headers" RETURN http::patch('https://dummyjson.com/comments/1', { "id": 1, "body": "This is some awesome thinking!", @@ -234,18 +268,6 @@ RETURN http::patch('https://dummyjson.com/comments/1', { }); ``` -```surql title="RESPONSE" -{ - "id": 1, - "body": "This is some awesome thinking!", - "postId": 100, - "user": { - "id": 63, - "username": "eburras1q" - } -} -``` - ```surql title="Setting the request headers" RETURN http::patch('https://dummyjson.com/comments/1', { "id": 1, @@ -274,9 +296,6 @@ RETURN http::patch('https://dummyjson.com/comments/1', { } ``` - - -
## `http::delete`