0

I'm building a small VS Code extension that takes the contents of the current editor tab in VS Code and posts it to a URL I specify somewhere (ideally in the VS Code UI via an input field).

What VS Code API would I use (or what other method) to make the REST API call - can I just use a regular Javascript fetch() or even JQuery?

Other issue is I need to authenticate access to the REST API I'm accessing, via regular user input on a web page, prior to POSTing (from JS etc) to the API - would that be possible (e.g. via a WebView in VSCode I guess) and then keep that authentication live to do the subsequent POSTs?

Thanks

Edit: Wondering if I can open a WebView to handle the initial web login and authentication by the user, then run some JS code inside the webview that gets the contents of the current editor tab and posts it to the REST API, would that be possible?

Alex Kerr
  • 956
  • 15
  • 44
  • have you looked at the source code of the postman extensions in the marketplace – rioV8 Nov 24 '21 at 13:41
  • Literally your extension is no other than a Node.js app, so duplicate to existing threads like https://stackoverflow.com/questions/5643321/how-to-make-remote-rest-call-inside-node-js-any-curl – Lex Li Nov 24 '21 at 14:07
  • @LexLi thanks - OK, but can you explain why please? I'm unfamiliar with how VS Code extensions work. Thanks – Alex Kerr Nov 24 '21 at 14:10
  • VSCode itself is an Electron application and relies on Node.js to implement many of its functionalities. Thus, all its extensions follow the same pattern, https://code.visualstudio.com/api/advanced-topics/extension-host It's only recently that the browser mode is added. – Lex Li Nov 24 '21 at 14:20

1 Answers1

0

I needed to solve the same problem, after a few experiments I chose the Axios library. It works well for me, example code here.

tuck1s
  • 1,002
  • 9
  • 28