Skip to content

Commit

Permalink
move examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwuno committed Jan 5, 2025
1 parent 3d834cc commit 726132b
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/content/doc-surrealql/functions/database/http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ 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
```

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!",
Expand All @@ -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!",
Expand All @@ -174,15 +191,15 @@ 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
```

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!",
Expand All @@ -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!",
Expand Down Expand Up @@ -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!",
Expand All @@ -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,
Expand Down Expand Up @@ -274,9 +296,6 @@ RETURN http::patch('https://dummyjson.com/comments/1', {
}
```




<br />

## `http::delete`
Expand Down

0 comments on commit 726132b

Please sign in to comment.