Skip to content

Commit

Permalink
Incorporate npx get-dtos to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 28, 2024
1 parent 92a1d09 commit e58cc4a
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 26 deletions.
15 changes: 15 additions & 0 deletions MyApp/_includes/npx-get-dtos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Alternative (without .NET): npx get-dtos

Alternatively API consumers can use [npx get-dtos](/npx-get-dtos) to Add/Update ServiceStack References without needing .NET installed, where any command starting with:

```txt
x <lang>
```

Can be replaced with:

```txt
npx get-dtos <lang>
```

To instead Add / Update ServiceStack references using the npm get-dtos package.
8 changes: 6 additions & 2 deletions MyApp/_pages/dart-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ Dart ServiceStack Reference supports **all Dart 2.0 platforms**, including Flutt
Due to the lack of reflection and Mirror support, consuming JSON APIs can be quite [cumbersome in Flutter](https://flutter.io/cookbook/networking/fetch-data/). But we've been able to achieve the same productive development experience available in [all supported languages](/add-servicestack-reference) where you can use the generated Dart DTOs from any remote v5.1+ ServiceStack endpoint with ServiceStack's Smart generic
[JsonServiceClient](https://pub.dartlang.org/documentation/servicestack/0.0.7/client/JsonServiceClient-class.html) available in the [servicestack Dart package](https://pub.dartlang.org/packages/servicestack#-installing-tab-), to enable an end-to-end Typed API for calling Services by [sending and receiving native DTOs](/architecture-overview#client-architecture).

### Example Usage
### Install

You can use the same [x dotnet tool](/dotnet-tool) simple command-line utility to easily Add and Update ServiceStack References for all supported languages:

Install [.NET Core](https://dotnet.microsoft.com/download) then install the `x` dotnet tool:
Install [.NET SDK](https://dotnet.microsoft.com/download) then install the `x` dotnet tool:

:::sh
dotnet tool install --global x
:::

::include npx-get-dtos.md::

### Example Usage

You can then execute `x dart` with the URL of the remote ServiceStack Instance you want to generated DTOs for, e.g:

:::sh
Expand Down
9 changes: 6 additions & 3 deletions MyApp/_pages/dotnet-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ title: ServiceStack's .NET Core Utility Belt

Our `x` and `app` dotnet tools are a versatile invaluable companion for all ServiceStack developers where it's
jam packed with functionality to power a number of exciting scenarios where it serves as a [Sharp App](https://sharpscript.net/docs/sharp-apps)
delivery platform where they can be run as a .NET Core Windows Desktop App with `app` or as a cross-platform Web App launcher
using `web` and we've already how it's now a [`#Script` runner](https://sharpscript.net/docs/sharp-scripts) with `x run` and into a
delivery platform where they can be run as a .NET Core Windows Desktop App with `app` or as a cross-platform Web App launcher using `web` and we've already how it's now a [`#Script` runner](https://sharpscript.net/docs/sharp-scripts) with `x run` and into a
[Live `#Script` playground](https://sharpscript.net/docs/sharp-scripts#live-script-with-web-watch) with `x watch`.

These tools contains all the functionality ServiceStack Developers or API consumers need that can be used
Expand All @@ -31,7 +30,11 @@ dotnet tool update -g x
:::

::: info
Both `x` and `app` have equivalent base functionality, whilst `app` has superset features for richer [Windows-only integration](/netcore-windows-desktop)
Both `x` and `app` have equivalent base functionality, whilst `app` has superset [Windows-only Desktop features](/netcore-windows-desktop)
:::

::: info
To update and download Add ServiceStack Reference dtos without .NET see [npx get-dtos](/npx-get-dtos)
:::

## Usage
Expand Down
2 changes: 2 additions & 0 deletions MyApp/_pages/javascript-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ npm install -D @servicestack/client

Where only its TypeScript definitions are used by the IDE during development to enable its type-checking and intelli-sense.

::include npx-get-dtos.md::

### Rich intelli-sense support

Where you'll be able to benefit from rich intelli-sense support in smart IDEs like [Rider](https://www.jetbrains.com/rider/) for
Expand Down
83 changes: 83 additions & 0 deletions MyApp/_pages/npx-get-dtos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Add ServiceStack Reference using npx get-dtos
---

To make it easier to consume ServiceStack APIs in any language, we've added the ability to download and upload Typed DTOs
in all languages without needing .NET installed with the new `npx get-dtos` npm script.

It has the same syntax and functionality as the `x` dotnet tool for adding and updating ServiceStack References where
in most cases you can replace `x <lang>` with `npx get-dtos <lang>` to achieve the same result.

Running `npx get-dtos` without any arguments will display the available options:

get-dtos <lang> Update all ServiceStack References in directory (recursive)
get-dtos <file> Update existing ServiceStack Reference (e.g. dtos.cs)
get-dtos <lang> <url> <file> Add ServiceStack Reference and save to file name
get-dtos csharp <url> Add C# ServiceStack Reference (Alias 'cs')
get-dtos typescript <url> Add TypeScript ServiceStack Reference (Alias 'ts')
get-dtos javascript <url> Add JavaScript ServiceStack Reference (Alias 'js')
get-dtos python <url> Add Python ServiceStack Reference (Alias 'py')
get-dtos dart <url> Add Dart ServiceStack Reference (Alias 'da')
get-dtos php <url> Add PHP ServiceStack Reference (Alias 'ph')
get-dtos java <url> Add Java ServiceStack Reference (Alias 'ja')
get-dtos kotlin <url> Add Kotlin ServiceStack Reference (Alias 'kt')
get-dtos swift <url> Add Swift ServiceStack Reference (Alias 'sw')
get-dtos fsharp <url> Add F# ServiceStack Reference (Alias 'fs')
get-dtos vbnet <url> Add VB.NET ServiceStack Reference (Alias 'vb')
get-dtos tsd <url> Add TypeScript Definition ServiceStack Reference

Options:
-h, --help, ? Print this message
-v, --version Print tool version version
--include <tag> Include all APIs in specified tag group
--qs <key=value> Add query string to Add ServiceStack Reference URL
--verbose Display verbose logging
--ignore-ssl-errors Ignore SSL Errors

### Reusable DTOs and Reusable Clients in any language

A benefit of [Add ServiceStack Reference](/add-servicestack-reference) is that only an
API DTOs need to be generated which can then be used to call any remote instance running that API. E.g. DTOs generated
for our deployed AI Server instance at [openai.servicestack.net](https://openai.servicestack.net) can be used to call
any self-hosted AI Server instance, likewise the same generic client can also be used to call any other ServiceStack API.

### TypeScript Example

For example you can get the TypeScript DTOs for the just released [AI Server](/posts/ai-server) with:

:::sh
`npx get-dtos typescript https://openai.servicestack.net`
:::

Which just like the `x` tool will add the TypeScript DTOs to the `dtos.ts` file

And later update all TypeScript ServiceStack References in the current directory with:

:::sh
`npx get-dtos typescript`
:::

### Install and Run in a single command

This can be used as a more flexible alternative to the `x` tool where it's often easier to install node in CI environments
than a full .NET SDK and easier to use npx scripts than global dotnet tools. For example you can use the `--yes` flag
to implicitly install (if needed) and run the `get-dtos` script in a single command, e.g:

:::sh
`npx --yes get-dtos typescript`
:::

### C# Example

As such you may want want to replace the `x` dotnet tool with `npx get-dtos` in your C#/.NET projects as well which
can either use the language name or its more wrist-friendly shorter alias, e.g:

:::sh
`npx get-dtos cs https://openai.servicestack.net`
:::

Then later update all C# DTOs in the current directory (including sub directories) with:

:::sh
`npx get-dtos cs`
:::
2 changes: 2 additions & 0 deletions MyApp/_pages/php-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ To install first install the [latest .NET SDK](https://dotnet.microsoft.com/down
$ dotnet tool install --global x
```

::include npx-get-dtos.md::

### Adding a ServiceStack Reference

To Add a PHP ServiceStack Reference just call `x php` with the URL of a remote ServiceStack instance:
Expand Down
2 changes: 2 additions & 0 deletions MyApp/_pages/python-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ To install first install the [latest .NET SDK](https://dotnet.microsoft.com/down
dotnet tool install --global x
:::

::include npx-get-dtos.md::

### Adding a ServiceStack Reference

To Add a Python ServiceStack Reference just call `x python` with the URL of a remote ServiceStack instance:
Expand Down
4 changes: 4 additions & 0 deletions MyApp/_pages/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
"text": "dotnet tool - Win/Mac/Linux Utils",
"link": "/dotnet-tool"
},
{
"text": "npx get-dtos",
"link": "/npx-get-dtos"
},
{
"text": "x new - Project Template",
"link": "/dotnet-new"
Expand Down
40 changes: 19 additions & 21 deletions MyApp/_pages/swift-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ $ dotnet tool install --global x

This will make the `x` dotnet tool available in your `$PATH` which can now be used from within a **Terminal window** at your Xcode project folder.

::include npx-get-dtos.md::

### Reference ServiceStack.Swift

To use the latest `JsonServiceClient` you'll need to add a reference to ServiceStack Swift library using your preferred package manager:

### Xcode
Expand All @@ -37,8 +41,7 @@ https://github.com/ServiceStack/ServiceStack.Swift

![](/img/pages/dev/xcode-add-servicestack-swift.png)

After adding the dependency both [ServiceStack.Swift](https://github.com/ServiceStack/ServiceStack.Swift) and its
[PromiseKit](https://github.com/mxcl/PromiseKit) dependency will be added to your project:
After adding the dependency [ServiceStack.Swift](https://github.com/ServiceStack/ServiceStack.Swift) will be added to your project:

![](/img/pages/dev/xcode-servicestack-swift-added.png)

Expand All @@ -50,20 +53,15 @@ In your [Podfile](https://guides.cocoapods.org/syntax/podfile.html):
use_frameworks!

# Pods for Project
pod "ServiceStack", '~> 1.1'
```

#### Carthage

```ruby
github "ServiceStack/ServiceStack.Swift" ~> 1.1
pod "ServiceStack", '~> 6.0.5'
```

#### SwiftPM

```swift
dependencies: [
.package(url: "https://github.com/ServiceStack/ServiceStack.Swift", from: "1.0.0"),
.package(url: "https://github.com/ServiceStack/ServiceStack.Swift.git",
Version(6,0,0)..<Version(7,0,0)),
],
```

Expand All @@ -74,11 +72,8 @@ Async usage example:
```swift
import ServiceStack

client.getAsync(AppOverview())
.done { r in
r.topTechnologies.count //= 100
//...
}
let response = try await client.getAsync(AppOverview())
print(response.topTechnologies.count) //= 100
```

Sync usage example:
Expand Down Expand Up @@ -167,22 +162,25 @@ The header comments in the generated DTO's allows for further customization of h

```swift
/* Options:
Date: 2017-02-02 02:41:09
SwiftVersion: 3.0
Version: 4.55
Date: 2024-11-28 10:23:42
SwiftVersion: 6.0
Version: 8.51
Tip: To override a DTO option, remove "//" prefix before updating
BaseUrl: https://techstacks.io
//BaseClass:
//AddModelExtensions: True
//AddServiceStackTypes: True
//MakePropertiesOptional: True
//IncludeTypes:
//ExcludeTypes:
//ExcludeGenericBaseTypes: True
//ExcludeGenericBaseTypes: False
//AddResponseStatus: False
//AddImplicitVersion:
//InitializeCollections: True
//DefaultImports: Foundation
//AddDescriptionAsComments: True
//InitializeCollections: False
//TreatTypesAsStrings:
//DefaultImports: Foundation,ServiceStack
*/
```

Expand Down
2 changes: 2 additions & 0 deletions MyApp/_pages/typescript-add-servicestack-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ The [dotnet tools](/dotnet-tool) include built in support for generating TypeScr
dotnet tool install --global x
:::

::include npx-get-dtos.md::

### Adding a ServiceStack Reference

To Add a TypeScript ServiceStack Reference just call `x typescript` with the URL of a remote ServiceStack instance:
Expand Down

0 comments on commit e58cc4a

Please sign in to comment.