Post

8. Generating code

Postman’s codegen feature

Postman can help you integrate API calls into your apps by generating code snippets in various coding languages.

Generating code snippets

Every request you made has a code generation tab you can access from the </> icon in the far right:

Once the code snippet generator pane is open, you can select from a dropdown to generate the API request in common coding languages:

For example, we can generate the GET /books request in curl syntax:

If we copy this snippet into the termial, we make the API call and the response body is printed:

1
2
3
4
5
$ curl --location 'https://library-api.postmanlabs.com/books' \
--header 'api-key: postmanrulz'

[{"id":"05388f9c-91bb-49c7-8db9-d178a297c66e","title":"To Kill a Mockingbird New","author":"Harper Lee","genre":"fiction","yearPublished":1960,"checkedOut":false,"isPermanentCollection":false,"createdAt":"2024-01-05T18:07:54.377Z"},{"id":"4bd4407f-a96a-4f1f-bc73-5b6e5b87f84a","title":"Rerum debitis neque expedita sit iure exercitationem sed.","author":"Rosa Kerluke III","genre":"self-help","yearPublished":117,"checkedOut":false,"isPermanentCollection":false,"createdAt":"2024-01-05T18:03:03.384Z"},{"id":"d92093d5-3c06-4a56-8eb8-a35f7aa375a8","title":"The Four Agreements","author":"don Miguel Ruiz","genre":"self-help","yearPublished":2023,"checkedOut":false,"isPermanentCollection":false,"createdAt":"2024-01-05T18:03:03.181Z"},{"id":"4604390e-6035-48f3-9f92-d574941b95d8","title":"The Pentester BluePrint: Starting a Career as an Ethical Hacker","author":"Phillip L. Wylie","genre":"Computer Security","yearPublished":2020,"checkedOut":false,"isPermanentCollection":false,"createdAt":"2024-01-05T18:01:23.822Z"},{"id":"1432a46c-f962-4343-94a5-744190d99481","title":"To Kill a Mockingbird New 1","author":"Harper Lee","genre":"fiction","yearPublished":1960,"checkedOut":false,"isPermanentCollection":false,"createdAt":"2024-01-05T17:30:28.962Z"},
<SNIP>
This post is licensed under CC BY 4.0 by the author.