|
| 1 | +--- |
| 2 | +title: Add ServiceStack Reference using npx get-dtos |
| 3 | +--- |
| 4 | + |
| 5 | +To make it easier to consume ServiceStack APIs in any language, we've added the ability to download and upload Typed DTOs |
| 6 | +in all languages without needing .NET installed with the new `npx get-dtos` npm script. |
| 7 | + |
| 8 | +It has the same syntax and functionality as the `x` dotnet tool for adding and updating ServiceStack References where |
| 9 | +in most cases you can replace `x <lang>` with `npx get-dtos <lang>` to achieve the same result. |
| 10 | + |
| 11 | +Running `npx get-dtos` without any arguments will display the available options: |
| 12 | + |
| 13 | + get-dtos <lang> Update all ServiceStack References in directory (recursive) |
| 14 | + get-dtos <file> Update existing ServiceStack Reference (e.g. dtos.cs) |
| 15 | + get-dtos <lang> <url> <file> Add ServiceStack Reference and save to file name |
| 16 | + get-dtos csharp <url> Add C# ServiceStack Reference (Alias 'cs') |
| 17 | + get-dtos typescript <url> Add TypeScript ServiceStack Reference (Alias 'ts') |
| 18 | + get-dtos javascript <url> Add JavaScript ServiceStack Reference (Alias 'js') |
| 19 | + get-dtos python <url> Add Python ServiceStack Reference (Alias 'py') |
| 20 | + get-dtos dart <url> Add Dart ServiceStack Reference (Alias 'da') |
| 21 | + get-dtos php <url> Add PHP ServiceStack Reference (Alias 'ph') |
| 22 | + get-dtos java <url> Add Java ServiceStack Reference (Alias 'ja') |
| 23 | + get-dtos kotlin <url> Add Kotlin ServiceStack Reference (Alias 'kt') |
| 24 | + get-dtos swift <url> Add Swift ServiceStack Reference (Alias 'sw') |
| 25 | + get-dtos fsharp <url> Add F# ServiceStack Reference (Alias 'fs') |
| 26 | + get-dtos vbnet <url> Add VB.NET ServiceStack Reference (Alias 'vb') |
| 27 | + get-dtos tsd <url> Add TypeScript Definition ServiceStack Reference |
| 28 | + |
| 29 | + Options: |
| 30 | + -h, --help, ? Print this message |
| 31 | + -v, --version Print tool version version |
| 32 | + --include <tag> Include all APIs in specified tag group |
| 33 | + --qs <key=value> Add query string to Add ServiceStack Reference URL |
| 34 | + --verbose Display verbose logging |
| 35 | + --ignore-ssl-errors Ignore SSL Errors |
| 36 | + |
| 37 | +### Reusable DTOs and Reusable Clients in any language |
| 38 | + |
| 39 | +A benefit of [Add ServiceStack Reference](/add-servicestack-reference) is that only an |
| 40 | +API DTOs need to be generated which can then be used to call any remote instance running that API. E.g. DTOs generated |
| 41 | +for our deployed AI Server instance at [openai.servicestack.net](https://openai.servicestack.net) can be used to call |
| 42 | +any self-hosted AI Server instance, likewise the same generic client can also be used to call any other ServiceStack API. |
| 43 | + |
| 44 | +### TypeScript Example |
| 45 | + |
| 46 | +For example you can get the TypeScript DTOs for the just released [AI Server](/posts/ai-server) with: |
| 47 | + |
| 48 | +:::sh |
| 49 | +`npx get-dtos typescript https://openai.servicestack.net` |
| 50 | +::: |
| 51 | + |
| 52 | +Which just like the `x` tool will add the TypeScript DTOs to the `dtos.ts` file |
| 53 | + |
| 54 | +And later update all TypeScript ServiceStack References in the current directory with: |
| 55 | + |
| 56 | +:::sh |
| 57 | +`npx get-dtos typescript` |
| 58 | +::: |
| 59 | + |
| 60 | +### Install and Run in a single command |
| 61 | + |
| 62 | +This can be used as a more flexible alternative to the `x` tool where it's often easier to install node in CI environments |
| 63 | +than a full .NET SDK and easier to use npx scripts than global dotnet tools. For example you can use the `--yes` flag |
| 64 | +to implicitly install (if needed) and run the `get-dtos` script in a single command, e.g: |
| 65 | + |
| 66 | +:::sh |
| 67 | +`npx --yes get-dtos typescript` |
| 68 | +::: |
| 69 | + |
| 70 | +### C# Example |
| 71 | + |
| 72 | +As such you may want want to replace the `x` dotnet tool with `npx get-dtos` in your C#/.NET projects as well which |
| 73 | +can either use the language name or its more wrist-friendly shorter alias, e.g: |
| 74 | + |
| 75 | +:::sh |
| 76 | +`npx get-dtos cs https://openai.servicestack.net` |
| 77 | +::: |
| 78 | + |
| 79 | +Then later update all C# DTOs in the current directory (including sub directories) with: |
| 80 | + |
| 81 | +:::sh |
| 82 | +`npx get-dtos cs` |
| 83 | +::: |
0 commit comments