Zum Hauptinhalt springen

Code generation

Postman is able to generate the relevant code to make requests in a variety of languages.

In this example, we will generate the appropriate authentication request for curl.

Re-run the authentication request from the collection:

code-generation

Then click on the 'Code' icon in the right sidebar:

code-generation icon

This pops up the Code snippet sidebar. curl should be selected by default; if not, then use the dropdown menu to select curl:

select-curl

Now we can see the set of curl commands that matches this Postman request:

curl-code

Let's authenticate again, by running the generated curl commands in a terminal:

curl-in-terminal

As you can see, we can make an equivalent request in curl.

This is valuable for bash scripts, where we can store the values of the tokens in variables. However, Postman does this automatically, which makes it a convenient tool with which to investigate APIs.