![]() Thunder Client is an alternative to the famous Postman tool used for testing client APIs. VS Code provides a marketplace of extensions that lets you easily search and download your favorite ones from the pool of many open-source options. It doesn't just let you write code in your preferred language(s) – it also lets you fast track the whole development process. VS Code is more than a code editor or IDE for so many developers. Preview of a sample request and response.How to download and install Thunder Client.You will not need to download any tools to do this, since you can get it done right within VS Code. Let's use the id of my favourite hero : Crystal Maiden.This article will teach you an alternative approach to testing client APIs using Thunder Client, an open-source extension available on VS Code marketplace. Now let's create en environment file and run all those calls for a given hero. Here is the generated code for the Heroes endpoints : Then, an Apis folder with all available calls and their related documentation.Each call is clickable and link to locations in our source code. First, a complete documentation with all available endpoints and how they work in the README.When we open the folder in IntelliJ, we're presented with a few very nice things ( Here is the GitHub repo if you want to see it for yourself): Then, we generate the client in a new folder $ openapi-generator generate -i -g jetbrains-http-client -o dotaClient First, we install the OpenAPI Generator $ brew install openapi-generator Let's generate a full HTTP Client for it. Let's have a quick look The beginning of the OpenAPI Spec fileĪs we can see, it describes the location of the API, as well as what kind of HTTP Calls you can make with the associated parameters. Conveniently, it provides us with an exhaustive OpenAPI specification file. I'm a big DOTA 2 player, and let's imagine I want to start playing with the Open DOTA API. As of yesterday, it's released! Let's look through it with an example! There is a great project for this, conveniently called OpenAPI Generator.ĭuring the Christmas holidays, I set myself on a quest to create a simple generator for the Jetbrains HTTP Client, which didn't exist yet. The nice thing about it is that you can then use this contract to automagically generate a lot of things for your API! That can be clients, in the language of your choice, mock servers, or even documentation. ![]() If you write a spec file for it, you basically write a "contract" for how your API works. It is basically a standard to describe your API. Many of you are probably aware of the OpenAPI specification (formerly swagger files). But wait, we can do much more! Generating full API Clients I hope that by this time you're convinced of the value of the Client □. The best thing about all this is that everything is a text file, so I can put my request file with its config in a folder in my repository, pushes it to my repository together with my source files and I suddenly have an easy way to interact with my API. Running the request with the slug set to ispum returns a valid response ![]() Running the request gets me the response, as expected, and it's even saved in a log file for me. You can either create a public file, or a private one for, say, API Keys. Pick an environment, and fill in a value for the variables you need. The one thing that I want to show you here is that it defines variables for you that you can fill in using a separate configuration file. You can do many things with those requests, like setting Content-Type, sending body payload and more but I'll direct you to the documentation for more. When clicking it, it will generate a scratch file for this request : The generated request The "Open in HTTP Client" option in the gutter of our IDE For example, looking at this Spring Boot Kotlin Sample, next to each Mapping there is a "Open in HTTP Client" option in the gutter. One thing I love about it is that it's integrated into the IDE, and it can generate those requests for you. Let's dive into how! A quick introduction to the Jetbrains HTTP ClientĪ lot of people don't know about the Jetbrains HTTP Client, which is a Jetbrains proprietary text file format that allows you to run API requests easily. With a combination of the Jetbrains HTTP Client and OpenAPI generators we can do much better, in a semi automated way and even reuse our code on our CI/CD. But I don't quite like the product any more, and it forces me to move out of my IntelliJ environment which really kills my productivity. Most people I know tend to use Postman for this. I work a lot with APIs, whether for an app I develop myself, or to interact with others. TL DR : I've created the first version of an openapi-generator for the jetbrains HTTP Client, and together with the CLI runner it allows you to play against APIs without ever going out of your terminal and it can even run in your CI/CD pipeline. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |