ChatiumFor developersPlaygroundPricing
Sign in

apiCall

A method for registering an API handler in the application. It binds a specific handler to a path template.

The method does not require module imports and is available globally in the application through the chatium object.

app.apiCall(pattern, handler)

Arguments

  1. pattern: string

    • The path template that the handler will respond to. The path is relative to the current router.
  2. handler: async function(ctx, req)

    • The function that handles the API call.

Examples


When the button is pressed, it shows the time in a popup message.

import {showToast} from '@app/ui'

app.apiCall('showTime', async (ctx, req) => {
  return showToast(new Date().toDateString())
})

app.screen('/', async (ctx, req) => {
  return (
    <screen>
      <button title="Show time" onClick={ctx.router.apiCall('/showTime')}/>
    </screen>
  )
})