The easiest way to call your APIs in a webpage is to include your JavaScript DTOs /types/js and built-in UMD @servicestack/client library:
<script src="/js/require.js"></script> <script src="/js/servicestack-client.js"></script> <script src="/types/js"></script>
We can then import and use the library and DTO types:
var { JsonServiceClient, Hello } = exports
var client = new JsonServiceClient()
client.api(new Hello({ name }))
.then(function(api) {
if (api.succeeded)
console.log(api.response)
})
Update your App's TypeScript DTOs and compile to JS (requires TypeScript):
$ x scripts dtos
Where you'll be able to use your APIs typed DTOs with ServiceStack's generic **JsonServiceClient**
$ npm install @servicestack/client
import { JsonServiceClient } from '@servicestack/client'
import { Hello } from './dtos'
let client = new JsonServiceClient()
let api = await client.api(new Hello({ name }))
if (api.succeeded)
console.log(api.response.result)
Typed DTOs generated using TypeScript Add ServiceStack Reference