Visual Studio Code Notebook and Restbook
VS notebook provider you editor to run your code in different languages to do your quick works very easily. You might have question, how it is different from other programing we already doing in VS code and answer is :
- Notebook provide you multiple cells for different purpose and mainly three sells i.e.
- Markdown --Is like description of your code you want to specify and you can write top/bottom area of your code.
- Code - Is your code you write and run.
- Output - Is output of your code when you run.
- Within one notebook file you can have multiple such cells/code-blocks and with each code block you can change the languages like one code block I want to run in javascript and one in python.
- And other benefit is, you can create your own custom notebook as per your business/project need to work with. So let say, you want to build notebook for your shopping cart project and there you want to give feature like add card, buy, view order etc.. So for them you can customize your notebook to define these methods and same you or any your team members use to full fill the business need.
- Other benefit I observed, it is very useful when you have data like csv or text file and you want to read and analyze data. Below is the example for this.
Now, let see how we can work with VS code notebook.
Be noted as on "22-May-2021" notebook feature still in development, so you need to use VS code insider latest version. If you do not have already on your system then download from there and install the same.
https://code.visualstudio.com/insiders/
Once you installed it, Open VS code insider and you need to install the notebook extension.
Note: There are multiple notebook extensions and mainly:
- Jupyter extension -https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
- .NET Interactive Notebooks -https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.dotnet-interactive-vscode
- Github Issues
Here we will run with Jupyter extension and same work as well, just that .net interactive notebook for .net language and Github issues is to filter tickets available in git hub for you.
So, install Jupyter extension
I am running python program in this example, so in case python is not installed then, download it from below link and install on your system:
https://www.python.org/downloads/
Post this, install python extension in VS code insider:
Now create Jupyter file, either you can press "CTRL + SHIP + P" and search for Jupyter and create file or just create manually with extension ".ipynb".
Refer below first program:
Next example is - I want to read csv file and display the result in output.
Here is my file sample:
Created notebook file, where I have created three code block, 1 for installing pandas package which provide reading file methods, 2 importing package and 3 using that package to read file and display output.
Additional note: with this example in first code block, I am using pip command to install package, so make sure during python installation this feature is checked otherwise, you can update/change the installation from control panel installed program.
By default it installed on the location: C:\Users\<user-name>\AppData\Local\Programs\Python\Python39\Scripts --here you will find pip.exe file
Also if you get unrecoganized command error when you run the code block then, do check the above pip path is set into your system environment variable path.
Rest book, this is like you can say postman tool, so you want to run/execute API through VS code. And this give you many features like
- You can run multiple API call using having multiple code blocks.
- You can declare variables and use those variables.
- You can use output of one API call to other etc..
To work with, make sure to install "Rest book" extension in your VS code insider: https://marketplace.visualstudio.com/items?itemName=tanhakabir.rest-book&WT.mc_id=-blog-scottha
Crate file with extension ".restbook" and it having again similar concept to create code block and run your code, refer below.
Categories/Tags: Visual Studio Code Notebook and Restbook~VS Code Notebook and Restbook