Class: HttpRequest
Main object for structuring a request.
Example
import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';
async function updateScore() {
const req = new HttpRequest('http://localhost:3000/updateScore');
req.body = JSON.stringify({
score: 22,
});
req.method = HttpRequestMethod.Post;
req.headers = [
new HttpHeader('Content-Type', 'application/json'),
new HttpHeader('auth', 'my-auth-token'),
];
await http.request(req);
}
Constructors
new HttpRequest()
new HttpRequest(
uri
):HttpRequest
Parameters
Parameter | Type |
---|---|
uri | string |
Returns
Properties
body
body:
string
Remarks
Content of the body of the HTTP request.
This property can't be edited in read-only mode.
headers
headers:
HttpHeader
[]
Remarks
A collection of HTTP headers to add to the outbound request.
This property can't be edited in read-only mode.
method
method:
HttpRequestMethod
Remarks
HTTP method (e.g., GET or PUT or PATCH) to use for making the request.
This property can't be edited in read-only mode.
timeout
timeout:
number
Remarks
Amount of time, in seconds, before the request times out and is abandoned.
This property can't be edited in read-only mode.
uri
uri:
string
Remarks
The HTTP resource to access.
This property can't be edited in read-only mode.
Methods
addHeader()
addHeader(
key
,value
):HttpRequest
Parameters
Parameter | Type |
---|---|
key | string |
value | string | SecretString |
Returns
Remarks
Adds an additional header to the overall list of headers used in the corresponding HTTP request.
This function can't be called in read-only mode.
setBody()
setBody(
body
):HttpRequest
Parameters
Parameter | Type |
---|---|
body | string |
Returns
Remarks
Updates the content of the body of the HTTP request.
This function can't be called in read-only mode.
setHeaders()
setHeaders(
headers
):HttpRequest
Parameters
Parameter | Type |
---|---|
headers | HttpHeader [] |
Returns
Remarks
Replaces and applies a set of HTTP Headers for the request.
This function can't be called in read-only mode.
setMethod()
setMethod(
method
):HttpRequest
Parameters
Parameter | Type |
---|---|
method | HttpRequestMethod |
Returns
Remarks
Sets the desired HTTP method (e.g., GET or PUT or PATCH) to use for making the request.
This function can't be called in read-only mode.
setTimeout()
setTimeout(
timeout
):HttpRequest
Parameters
Parameter | Type |
---|---|
timeout | number |
Returns
Remarks
This function can't be called in read-only mode.