Nova · Endpoints

HTTP endpoint

An endpoint that names a URL. The address is a template over the action’s data, and onSuccess runs once the answer has been written to target.

The action, as it is written
{
  id: 'http-endpoint',
  data: {
    id: 'm1',
    state: 'not asked',
    member: { name: '', pass: '' },
  },
  layout: {
    component: 'Stack',
    children: [
      { component: 'Text', children: 'State: {{$.state}}' },
      {
        if: '$.member.name',
        then: {
          component: 'Text',
          children: '{{$.member.name}} has a {{$.member.pass}} pass.',
        },
      },
      {
        component: 'Button',
        ref: 'load',
        children: 'Look the member up',
      },
    ],
  },
  endpoints: {
    member: {
      url: '/examples/http-endpoint/members/{{$.id}}',
      method: 'GET',
      target: 'member',
    },
  },
  triggers: [
    {
      event: 'ui:click',
      ref: 'load',
      do: [
        { set: 'state', value: 'asking' },
        {
          call: 'member',
          onSuccess: [{ set: 'state', value: 'answered' }],
        },
      ],
    },
  ],
}
Running herepress it

State: not asked

What its endpoints are answered
{
  GET /examples/http-endpoint/members/m1: { status: 200, body: { name: 'Ada', pass: 'season' } },
}
What is done to it
press load
What it sent
[
  {
    method: 'GET',
    url: '/examples/http-endpoint/members/m1',
  },
]
What it then holds
{
  id: 'm1',
  state: 'answered',
  member: { name: 'Ada', pass: 'season' },
}
What it then says
State: answered
Ada has a season pass.
Look the member up
Output matches the expected value

Left: the action as the package ships it. Right: the same action running in this page, rendered with this site’s components. Below: the action run as the example specifies, on the installed package.