Hello API

Using JsonServiceClient in Web Pages

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>
  var exports = { __esModule:true }, module = { exports:exports }
  function require(name) { return exports[name] || window[name] }
</script>
<script src="/js/servicestack-client.js"></script>
<script src="/types/js"></script>

We can then import the library and DTO types in the global namespace to use them directly:

Object.assign(window, exports) //import

var client = new JsonServiceClient()
client.api(new Hello({ name: name }))
    .then(function(api) {
        if (api.succeeded) 
            console.log(api.response.result)
    })

Using @servicestack/client in npm projects

Update your App's TypeScript DTOs and compile to JS (requires TypeScript):

$ x scripts dtos

Including @servicestack/client & Typed DTOs

Create a basic UMD loader then include the UMD @servicestack/client library and dtos.js:

$ npm install @servicestack/client
import { JsonServiceClient } from '@servicestack/client'

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