|
| 1 | +<div align="center"> |
| 2 | + <h1>trpc-postman</h1> |
| 3 | + <a href="https://www.npmjs.com/package/trpc-postman"><img src="https://img.shields.io/npm/v/trpc-postman.svg?style=flat&color=brightgreen" target="_blank" /></a> |
| 4 | + <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-black" /></a> |
| 5 | +</div> |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Generate an Postman spec from your tRPC server, in one line of code |
| 10 | + |
| 11 | +### Step 1: Install `trpc-postman` |
| 12 | + |
| 13 | +```bash |
| 14 | +# npm |
| 15 | +npm install trpc-postman |
| 16 | + |
| 17 | +# yarn |
| 18 | +yarn install trpc-postman |
| 19 | + |
| 20 | +# pnpm |
| 21 | +pnpm install trpc-postman |
| 22 | +``` |
| 23 | + |
| 24 | +### Step 2: Generate Postman Collection |
| 25 | + |
| 26 | +```typescript |
| 27 | +import { trpcToPostmanCollection } from "trpc-postman"; |
| 28 | + |
| 29 | +// generate Postman Collection JSON |
| 30 | +const postmanCollection = trpcToPostmanCollection({ |
| 31 | + collectionName: "My API", |
| 32 | + router: trpcRouter, |
| 33 | +}); |
| 34 | +``` |
| 35 | + |
| 36 | +## Publishing the Postman Collection |
| 37 | + |
| 38 | +You can update your Postman Collection using your Postman API key and Collection ID |
| 39 | + |
| 40 | +### Step 1: Generate a Postman API key |
| 41 | + |
| 42 | +You can generate a Postman API key [here](https://www.postman.com/settings/me/api-keys). |
| 43 | + |
| 44 | +### Step 2: Get your Colllection ID |
| 45 | + |
| 46 | +If you don't already have a collection to publish to, create a collection manually. |
| 47 | + |
| 48 | +Then, you can see your Collection ID by clicking the `i` button on the right-hand side: |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +### Step 3: Publish collection |
| 53 | + |
| 54 | +> WARNING!! This will ERASE your entire collection with the generated Postman Collection. |
| 55 | +
|
| 56 | +```typescript |
| 57 | +import { trpcToPostmanCollection } from "trpc-postman"; |
| 58 | + |
| 59 | +// generate Postman Collection JSON |
| 60 | +const postmanCollection = trpcToPostmanCollection({ |
| 61 | + collectionName: "My API", |
| 62 | + router: trpcRouter, |
| 63 | +}); |
| 64 | + |
| 65 | +// overwrite collection in postman |
| 66 | +await updateRemotePostmanCollection({ |
| 67 | + apiKey: POSTMAN_API_KEY, |
| 68 | + collectionId: YOUR_COLLECTION_ID, |
| 69 | + collection: postmanCollection, |
| 70 | +}); |
| 71 | +``` |
0 commit comments