a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Server / makeRequest
makeRequest<
T
>(url
,method
,data
?,headers
?):Promise
<T
>
A general-purpose function for making HTTP requests.
This function performs HTTP requests using the Fetch API. It supports various HTTP methods (GET, POST, PUT, DELETE) and allows you to include request headers and body data.
• T
• url: string
The URL to which the request is sent.
string
• method: RequestMethods
= 'GET'
The HTTP method to use for the request.
RequestMethods
(a type alias for 'GET' | 'POST' | 'PUT' | 'DELETE'
)'GET'
'GET'
if not specified.• data?: RequestData
The request body data.
RequestData
(an interface where keys are strings and values can be any type)undefined
• headers?: RequestHeaders
= {}
Optional headers to include in the request.
RequestHeaders
(an interface where keys are strings and values are strings){}
Content-Type
header is automatically set to 'application/json'
.Promise
<T
>
A promise that resolves to the response data of type T
.
Promise<T>
T
.Throws an error if the response status is not OK or if there is an error during the fetch operation.
interface User {
id: number;
name: string;
}
async function fetchUser() {
try {
const user = await makeRequest<User>('https://api.example.com/user/1');
console.log(user);
} catch (error) {
console.error('Error fetching user:', error);
}
}