--- title: ES6 Class Add ServiceStack Reference --- In addition to [TypeScript](/typescript-add-servicestack-reference) support for generating typed Data Transfer Objects (DTOs), JavaScript is now supported in the form of [JSDoc](https://jsdoc.app) annotated typed ES6 classes that can be referenced natively from [JavaScript Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). ### Reference directly in JavaScript Modules Unlike TypeScript, the JavaScript ES6 class DTOs can be referenced directly in a browser as-is, removing the need to keep your DTOs in sync with extra tooling by direct referencing them in a JavaScript Module: ```html ``` Then to make typed API Requests from web pages, you need only need to reference an ES Module (.mjs) build of the dependency-free [@servicestack/client](https://github.com/ServiceStack/servicestack-client) library which can be sourced directly from a npm CDN: ```html ``` ### Import Maps Although we recommend using an [importmap](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) to specify where to load **@servicestack/client** from, e.g: ```html ``` ### ImportMap in Razor Pages or MVC Razor Pages or MVC projects can use `@Html.ImportMap()` in **_Layout.cshtml** to use different builds for development and production, e.g: ```csharp @if (Context.Request.Headers.UserAgent.Any(x => x.Contains("Safari") && !x.Contains("Chrome"))) { } @Html.ImportMap(new() { ["@servicestack/client"] = ("/js/servicestack-client.mjs", "/js/servicestack-client.min.mjs"), }) ``` ### Usage This lets us reference the **@servicestack/client** package name in our source code instead of its physical location: ```html
``` ```html ``` ### Enable static analysis and intelli-sense For better IDE intelli-sense during development, save the annotated Typed DTOs to disk with the [x dotnet tool](/dotnet-tool): :::sh x mjs ::: Then reference it instead to enable IDE static analysis when calling Typed APIs from JavaScript: ```js import { Hello } from '/js/dtos.mjs' client.api(new Hello({ name })) ``` To also enable static analysis for **@servicestack/client**, install the dependency-free library as a dev dependency: :::sh 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 both the client library:  As well as your App's server generated DTOs:  ## Add ServiceStack Reference A new ServiceStack reference containing the APIs typed DTOs can be added using the **BaseUrl** of the ServiceStack App, e.g: :::sh `x mjs https://localhost:5001` ::: ### Update ServiceStack References All existing ServiceStack References can later be updated with: :::sh x mjs ::: ## DTO Customization Options In most cases you'll just use the generated JavaScript DTO's as-is, however you can further customize how the DTOs are generated by overriding the default options. The header in the generated DTOs show the different options JavaScript types support with their defaults. Default values are shown with the comment prefix of `//`. To override a value, remove the `//` and specify the value to the right of the `:`. Any uncommented value will be sent to the server to override any server defaults. The DTO comments allows for customizations for how DTOs are generated. The default options that were used to generate the DTOs are repeated in the header comments of the generated DTOs, options that are preceded by a TypeScript comment `//` are defaults from the server, any uncommented value will be sent to the server to override any server defaults. ```js /* Options: Date: 2025-06-04 09:52:13 Version: 8.80 Tip: To override a DTO option, remove "//" prefix before updating BaseUrl: https://blazor-vue.web-templates.io //AddServiceStackTypes: True //AddDocAnnotations: True //AddDescriptionAsComments: True //IncludeTypes: //ExcludeTypes: //DefaultImports: */ ``` We'll go through and cover each of the above options to see how they affect the generated DTO's: ### Change Default Server Configuration The above defaults are also overridable on the ServiceStack Server by modifying the `NativeTypesFeature` Plugin, e.g: ```csharp //Server example in CSharp var nativeTypes = this.GetPlugin