Jump to content

AWESOME feature in VisualStudio for testing API Endpoints


Cheesegeezer

Recommended Posts

Cheesegeezer

I just stumbled across this excellent "hidden" feature in Visual Studio.  Which lets you test api endpoints without having to run code for testing or even use Swagger to return jsons.  It's simply a http file extension.

Its epic!! Let me show you....

  1. Create a new folder in your project and call it API Playground or something like that
  2. Right click folder and add new item and in C# items you should see http file
  3. image.png.a7ef730960f77dc7cfd6d33a439edb84.png

 

  1. Select HTTP File and give it a name like Emby API Endpoints
  2. once created you can use GET POST PUT & DELETE requests to test any endpoint.

you can create and use variables. you just need to add the @ symbol before the name of your variable and to use it in your request you need enclose the variable name in DOUBLE curly braces.... {{myVariable}}

To add multiple end point tests you need to do a triple hash key under each request ###

and to comment you just need a single # prefix

image.png.40ebec469dc2f5107521e56952d857b3.png

 

Click the little play icon next to the Endpoint you want to test and boom you will get all the info you need in a json right next to it!!!

image.thumb.png.9940db46ab5dd6bb02dea7fcac8b5e2e.png

 

It's so cool, i didn't know about this amazing feature and wow does it speed up work flow.  You can also copy the full json and then create new ModelDto's without even leaving VS!!! 

@chef  @VicMoore  @TeamB @ginjaninja @mickle026   @BillOatman

This is true Wizardry!!! I'm sure you all knew about it, but i just wanted to share this!!

 

Hope it helps someone else out.

Edited by Cheesegeezer
  • Like 5
Link to comment
Share on other sites

Or you download the Emby.SDK which contains two different C# libraries, both of them cover the complete REST API and include ready-to-use fully-typed classes for every single request and response you can make:

Download: https://dev.emby.media/download/index.html

Link to comment
Share on other sites

Cheesegeezer
5 minutes ago, softworkz said:

Or you download the Emby.SDK which contains two different C# libraries, both of them cover the complete REST API and include ready-to-use fully-typed classes for every single request and response you can make:

Download: https://dev.emby.media/download/index.html

Yes i agree, the point of my post was testing the end points not acquiring the endpoints. Although i used Emby as an example… lets say you wanted to use the TMDB API that doesn’t provide a fully rounded SDK. 
 

 

  • Like 1
Link to comment
Share on other sites

Cheesegeezer
5 minutes ago, softworkz said:

Yup, that's surely nice. Hadn't seen this before either!

It will certainly speed up IMetadataProvider development for you guys and plugin devs!! 
 

Link to comment
Share on other sites

1 minute ago, Cheesegeezer said:

It will certainly speed up IMetadataProvider development for you guys and plugin devs!! 
 

Well - you don't use REST APIs when developing metadata providers and server plugins...

Link to comment
Share on other sites

Ah, you mean for accessing external APIs?

Yes, maybe.

I can show you another trick for that:

  • Just run an URL from their documentation in the browser
  • For example, in case of TV-Maze: https://api.tvmaze.com/seasons/1/episodes?embed[]=guestcrew
  • Copy the full json output from the browser
  • In Visual Studio, create a new class file and delete the class
  • Then Edit => Paste Special => Paste JSON as Classes
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Cheesegeezer
1 hour ago, softworkz said:

Ah, you mean for accessing external APIs?

Yes, maybe.

I can show you another trick for that:

  • Just run an URL from their documentation in the browser
  • For example, in case of TV-Maze: https://api.tvmaze.com/seasons/1/episodes?embed[]=guestcrew
  • Copy the full json output from the browser
  • In Visual Studio, create a new class file and delete the class
  • Then Edit => Paste Special => Paste JSON as Classes

I know that one haha use it a lot!! Works for xml files too as there is an option to paste those too!

but.. using the http file and running the endpoint inside VS, your json is populated right next to it in a pane. You can copy the json from that pane inside VS and create a new class and paste as you described. Change RootObject class name to something more sensible.

I didn’t even leave VS to achieve the same as what you just did hehe 😉 

Edited by Cheesegeezer
  • Like 1
Link to comment
Share on other sites

BillOatman

Visual Studio Code also has restclient as a plugin.  That's what I tend to use because it's lightweight and it can run on 1 monitor while I have the others for the VS debugger.

 

 

  • Like 1
Link to comment
Share on other sites

mickle026

I dont have http file in visual studio, I cannot find what it bundled with to install it either.

I have vs 2019 enterprise, which version do you have?

Edited by mickle026
Link to comment
Share on other sites

Cheesegeezer
1 hour ago, mickle026 said:

I dont have http file in visual studio, I cannot find what it bundled with to install it either.

I have vs 2019 enterprise, which version do you have?

 

1 hour ago, mickle026 said:

I dont have http file in visual studio, I cannot find what it bundled with to install it either.

I have vs 2019 enterprise, which version do you have?

You probably need 2022 17.4 in order to reap the benefits of this. It may even be 17.5

i keep upto date because I’m developing in dotNet Maui and those updates come thick n fadt lol 😂 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...