I wonder though if there is a plain an simple way from within TypeScript to consume a REST API.
Lets simplify REST API
to be *I want to make GET
and POST
requests. The fact that it is a REST
style API is not relevant.
I want to make GET
and POST
requests
Native ways of doing this depends on the JavaScript environment. e.g. Browser's traditional API has been XMLHttpRqeuest
: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest which is fully supported by TypeScript. A newer API is fetch
which is also supported by TypeScript but might not be supported by the browser you are targetting.
On node you would use http
module https://nodejs.org/api/http.html
Suggestion
Now if you want an API that works across both node and old browsers you will need some library that abstracts the native features. One suggestion is axios which works with TypeScript out of the box.