DEV Community

Praneet Nadkar
Praneet Nadkar

Posted on

3 1

Generating code to call a request from Postman

Postman is one of the best tools I have used to call, test and debug my API(s). This morning when I was going through something, I found two brilliant features in postman I wasn't aware of. Postman can generate some request calling code for you and can generate documentation as well. For those who aren't aware, Yes that's true!

I have created a sample API in C#, which looks like this:

// POST api/values
[HttpPost]
public ActionResult<string> Post([FromBody] string value)
{
   return ""+value+" is posted";
}
Enter fullscreen mode Exit fullscreen mode

Now to call this API in Postman, it will look something like this:

Post API

Now, to generate some code on to call this request, there is a Code button on the top right. Click on it to see the options where you can see a no of languages to generate the code. It looks something like this:

Code button in postman

When you click on this code button, a pop-up menu like this will appear:

Code clicked

Now, you can see there is a code snippet and a drop down from where you can select a no of options, as to for which you want to generate the code. The options available are:

code_options

Now, click on any of the options, where you will see the code. Copy the code and paste it in your IDE and run!

It would look something like this:
code_snippet

It's done! As simple as that.

API Trace View

Struggling with slow API calls? πŸ•’

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (1)

Collapse
 
avinash905 profile image
Dunna Avinash β€’

How can I generate code for an entire collection at once?

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay