Send HTTPS request
Sending HTTP/HTTPS requests is a common task in application development, in this turorial we will show you how to send HTTPS requests.
Prerequisites
Prepare a HTML to execute:
html
<html>
<head>
<title>Send HTTPS request</title>
<script type="module" src="./main.ts"></script>
</head>
<body>
</body>
</html>
Using fetch
API
Now you could write your main.ts
to send HTTPS request:
typescript
(async () => {
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const json = await response.json();
console.log(json);
})();
If you are a Web developer, and have experience with fetch
API, you will find it is the same as in the browser.
Run the code
Now you can run the code in a JSAR environment such as Play WebXR, and you will see the response in the console.
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}