Skip to content

Commit c19f33e

Browse files
committed
Request category update
1 parent ddebeed commit c19f33e

6 files changed

Lines changed: 191 additions & 204 deletions

File tree

guide/Request/httpRequest.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# $httpRequest
2-
3-
Perform an http request, with a content and headers and return the response content
4-
5-
## Usage
6-
7-
```bash
8-
$httpRequest[URL;Method;Content;Header 1;Header 2;...]
9-
```
10-
11-
### Methods:
12-
Accepts PUT, GET, POST, DELETE, HEAD, PATCH methods, if not provided, it will use GET method
13-
14-
### Content Input:
15-
It can any content that suitable for your `content-type` header, like with `content-type: application/json` you can put the content as json format and so on
16-
17-
### Header:
18-
It accept the header in format of header: value\
19-
for example: `Content-Type: application/json`
20-
21-
### Example (Sending JSON Request):
22-
<discord-messages>
23-
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
24-
!!exec $let[response;$httpRequest[My API URL;post;{"name":"Mido"};Content-Type: application/json]]<br>Response is $response<br>Response Status is $httpRequestStatus<br><br>
25-
</discord-message>
26-
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
27-
Response is {"success":true}<br>Response Status is 200<br><br>
28-
</discord-message>
29-
</discord-messages>
30-
31-
### Some Notes:
32-
* This function wont throw error if request non-ok status, so please check on your own the return value of $httpRequestStatus after the request to make sure its valid status you expecting
1+
# $httpRequest
2+
3+
Perform an http request, with a content and headers and return the response content
4+
5+
## Usage
6+
7+
```bash
8+
$httpRequest[URL;Method;Content;Header 1;Header 2;...]
9+
```
10+
11+
### Methods:
12+
Accepts PUT, GET, POST, DELETE, HEAD, PATCH methods, if not provided, it will use GET method
13+
14+
### Content Input:
15+
It can any content that suitable for your `content-type` header, like with `content-type: application/json` you can put the content as json format and so on
16+
17+
### Header:
18+
It accept the header in format of header: value\
19+
for example: `Content-Type: application/json`
20+
21+
### Example (Sending JSON Request):
22+
<discord-messages>
23+
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
24+
!!exec $let[response;$httpRequest[My API URL;post;{"name":"Mido"};Content-Type: application/json]]<br>Response is $response<br>Response Status is $httpRequestStatus<br><br>
25+
</discord-message>
26+
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
27+
Response is {"success":true}<br>Response Status is 200<br><br>
28+
</discord-message>
29+
</discord-messages>
30+
31+
### Some Notes:
32+
* This function wont throw error if request non-ok status, so please check on your own the return value of $httpRequestStatus after the request to make sure its valid status you expecting
3333
* Make sure the response data length is less than 1 MB, or it will errorRandom

guide/Request/httpRequestHeader.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# $httpRequestHeader
2-
3-
return the header values from the most recent request performed with $httpRequest
4-
5-
## Usage
6-
7-
```bash
8-
$httpRequestHeader[header name]
9-
```
10-
11-
### Example:
12-
<discord-messages>
13-
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
14-
!!exec $let[response;$httpRequest[My API URL]]<br>Response Content type is $httpRequestHeader[content-type]<br><br>
15-
</discord-message>
16-
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
17-
Response Content type is application/json
18-
</discord-message>
1+
# $httpRequestHeader
2+
3+
return the header values from the most recent request performed with $httpRequest
4+
5+
## Usage
6+
7+
```bash
8+
$httpRequestHeader[header name]
9+
```
10+
11+
### Example:
12+
<discord-messages>
13+
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
14+
!!exec $let[response;$httpRequest[My API URL]]<br>Response Content type is $httpRequestHeader[content-type]<br><br>
15+
</discord-message>
16+
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
17+
Response Content type is application/json
18+
</discord-message>
1919
</discord-messages>
Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
1-
# $httpRequestHeader
2-
3-
Retrieves the value of a specific header from the most recent HTTP request made using the `$httpRequest` function.
4-
5-
## Syntax
6-
7-
```bash
8-
$httpRequestHeader[header name]
9-
```
10-
11-
**`header name`**: The name of the HTTP header you want to retrieve. This is case-insensitive.
12-
13-
## Description
14-
15-
This function allows you to access the headers returned by the server after making an HTTP request with `$httpRequest`. You can use this to inspect the response and handle it accordingly. Common headers include `content-type`, `content-length`, `date`, and `server`.
16-
17-
**Important:** This function only works if a successful `$httpRequest` has been made *before* it's called within the same execution context.
18-
19-
## Example
20-
21-
This example makes an HTTP request and then retrieves and displays the `content-type` header from the response.
22-
23-
```discord
24-
!!exec $let[response;$httpRequest[My API URL]]
25-
Response Content type is $httpRequestHeader[content-type]
26-
```
27-
28-
Here's a breakdown of what's happening:
29-
30-
1. `$let[response;$httpRequest[My API URL]]`: This first makes an HTTP request to "My API URL" (replace this with an actual URL). The response is stored in a variable called `response`. While the response itself is stored, the crucial part here is that `$httpRequest` is executed and its headers become available.
31-
32-
2. `Response Content type is $httpRequestHeader[content-type]`: This retrieves the value of the `content-type` header from the previous `$httpRequest` call and includes it in the message.
33-
34-
**Example Output:**
35-
36-
<discord-messages>
37-
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
38-
!!exec $let[response;$httpRequest[My API URL]]<br>Response Content type is $httpRequestHeader[content-type]<br><br>
39-
</discord-message>
40-
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
41-
Response Content type is application/json
42-
</discord-message>
43-
</discord-messages>
44-
45-
**Note:** Replace `My API URL` with a valid URL in your actual command. The output `application/json` is just an example; the actual value will depend on the API you're querying.
1+
# $httpRequestHeader
2+
3+
Returns the value of a given header from the last request.
4+
5+
## Usage
6+
7+
```bash
8+
$httpRequestHeader[header name]
9+
```
10+
1. **header name** - The header name to return value from. (case-insensitive)
11+
12+
## Example
13+
14+
#### Using $httpRequestHeader
15+
16+
How to return Content-Type from last request
17+
18+
<discord-messages>
19+
<discord-message :bot="false" role-color="#d6e0ff" author="User" avatar="https://cdn.discordapp.com/embed/avatars/0.png">
20+
!!exec $httpRequest[https://api.example.com/]<br>
21+
Content-Type Header: $httpRequestHeader[content-type]
22+
</discord-message>
23+
<discord-message :bot="true" role-color="#5fb0fa" author="Custom Command" avatar="https://doc.ccommandbot.com/bot-profile.png">
24+
{"message": "Api response!"}<br>
25+
Content-Type Header: application/json
26+
</discord-message>
27+
</discord-messages>
28+
29+
##### Related functions: [$httpRequest](../Request/httpRequest.md) [$httpRequestStatus](../Request/httpRequestStatus.md)
30+
31+
##### Function difficulty: <Badge type="warning" text="Medium" vertical="middle"/>
32+
###### Tags: <Badge type="tip" text="http request" vertical="middle"/> <Badge type="tip" text="api request" vertical="middle"/> <Badge type="tip" text="header" vertical="middle"/>

guide/Request/httpRequestStatus.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# $httpRequestStatus
2-
3-
return the request status from the most recent request performed with $httpRequest
4-
5-
## Usage
6-
7-
```bash
8-
$httpRequestStatus
9-
```
10-
11-
### Example:
12-
<discord-messages>
13-
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
14-
!!exec $let[response;$httpRequest[My API URL]]<br>Request status is $httpRequestStatus<br><br>
15-
</discord-message>
16-
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
17-
Request Status is 200<br><br>
18-
</discord-message>
19-
</discord-messages>
20-
21-
### Note:
1+
# $httpRequestStatus
2+
3+
return the request status from the most recent request performed with $httpRequest
4+
5+
## Usage
6+
7+
```bash
8+
$httpRequestStatus
9+
```
10+
11+
### Example:
12+
<discord-messages>
13+
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
14+
!!exec $let[response;$httpRequest[My API URL]]<br>Request status is $httpRequestStatus<br><br>
15+
</discord-message>
16+
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
17+
Request Status is 200<br><br>
18+
</discord-message>
19+
</discord-messages>
20+
21+
### Note:
2222
Its recommended to check the request status directly after $httpRequest, to check if it was valid status.
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
# `$httpRequestStatus`
2-
3-
Returns the HTTP status code of the most recent request made using the `$httpRequest` function.
4-
5-
## Description
6-
7-
This function allows you to check the outcome of your HTTP request, helping you handle success and error scenarios.
8-
9-
## Usage
10-
11-
```bash
12-
$httpRequestStatus
13-
```
14-
15-
## Example
16-
17-
This example demonstrates how to use `$httpRequest` and `$httpRequestStatus` to make an API request and check its success.
18-
19-
<discord-messages>
20-
<discord-message :bot="false" role-color="#ffcc9a" author="Member">
21-
!!exec $let[response;$httpRequest[My API URL]]<br>Request status is $httpRequestStatus
22-
</discord-message>
23-
<discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp">
24-
Request Status is 200
25-
</discord-message>
26-
</discord-messages>
27-
28-
**Explanation:**
29-
30-
1. `$let[response;$httpRequest[My API URL]]`: This line makes an HTTP request to the specified "My API URL" using `$httpRequest` and stores the response (if any) into the `response` variable.
31-
2. `Request status is $httpRequestStatus`: This retrieves the HTTP status code of the previous `$httpRequest` call using `$httpRequestStatus` and displays it. In this example, the status code is `200`, which typically indicates a successful request.
32-
33-
## Important Note
34-
35-
It's highly recommended to check the `$httpRequestStatus` immediately after using `$httpRequest`. This allows you to verify if the request was successful before proceeding with further actions based on the response. For example, you can use this to conditionally execute code based on whether the API call returned a 200 OK or an error code like 404 or 500.
1+
# $httpRequestStatus
2+
3+
Returns the $httpRequest status code of the last request.
4+
5+
## Usage
6+
7+
```bash
8+
$httpRequestStatus
9+
```
10+
11+
## Example
12+
13+
#### Using $httpRequestStatus
14+
15+
How to use $httpRequestStatus to display status code of request
16+
17+
<discord-messages>
18+
<discord-message :bot="false" role-color="#d6e0ff" author="User" avatar="https://cdn.discordapp.com/embed/avatars/0.png">
19+
!!exec $httpRequest[https://api.example.com/]<br>
20+
Code: $httpRequestStatus
21+
</discord-message>
22+
<discord-message :bot="true" role-color="#5fb0fa" author="Custom Command" avatar="https://doc.ccommandbot.com/bot-profile.png">
23+
Api response!<br>
24+
Code: 200
25+
</discord-message>
26+
</discord-messages>
27+
28+
##### Related functions: [$httpRequest](../Request/httpRequest.md) [$httpRequestHeader](../Request/httpRequestHeader.md)
29+
30+
##### Function difficulty: <Badge type="warning" text="Medium" vertical="middle"/>
31+
###### Tags: <Badge type="tip" text="http request" vertical="middle"/> <Badge type="tip" text="api request" vertical="middle"/> <Badge type="tip" text="status" vertical="middle"/>

0 commit comments

Comments
 (0)