In JavaScript, you can make an HTTP request using the built-in XMLHttpRequest
object or the newer fetch()
API. Here's an example of how to make a GET request using both methods:
Using XMLHttpRequest:
Using fetch():
In both examples, we are making a GET request to the URL https://example.com/api/data
and logging the response to the console. You can modify the URL and the type of request (e.g., POST, PUT, DELETE) as needed.