make a http get request in typescript

To make an HTTP GET request in TypeScript, you can use the built-in fetch API provided by modern browsers. This API uses promises to manage asynchronous operations, making HTTP requests much simpler than older methods.

Here's an example code snippet that demonstrates how to make a basic HTTP GET request using fetch:

index.ts
fetch('https://jsonplaceholder.typicode.com/users')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));
165 chars
5 lines

In this example, we use the fetch method to make an HTTP GET request to the JSONPlaceholder API, which returns a list of user objects. We then call the json method on the response object to parse the response data as JSON. Finally, we log the resulting data to the console. Note that we also include a catch block to handle any errors that may occur during the request.

This is just a basic example, and there are many more advanced features that you can use with the fetch API to customize your HTTP requests. For more information, check out the official Fetch API documentation.

gistlibby LogSnag