Nova · Endpoints

Request and headers

What is sent is declared on the endpoint. A header is a template over the action’s data, and request is a transform that builds the body from that data, so nothing but what it names leaves the action. response is a transform over what comes back, before it is written to target.

The action, as it is written
{
  id: 'endpoint-request',
  data: {
    token: 'box-office',
    member: 'm1',
    seats: ['C4', 'C5'],
    note: 'not for the server',
    booking: '',
  },
  layout: {
    component: 'Stack',
    children: [
      {
        if: '$.booking',
        then: {
          component: 'Text',
          children: 'Booked as {{$.booking}}.',
        },
      },
      {
        component: 'Button',
        ref: 'book',
        children: 'Book both seats',
      },
    ],
  },
  endpoints: {
    book: {
      url: '/examples/endpoint-request/bookings',
      method: 'POST',
      headers: { authorization: 'Bearer {{$.token}}' },
      request: {
        member: { $ref: '$.member' },
        seats: { $length: { $ref: '$.seats' } },
      },
      response: { $ref: '$.id' },
      target: 'booking',
    },
  },
  triggers: [
    {
      event: 'ui:click',
      ref: 'book',
      do: [{ call: 'book' }],
    },
  ],
}
Running herepress it
What its endpoints are answered
{
  POST /examples/endpoint-request/bookings: { status: 200, body: { id: 'B-2041', seats: 2 } },
}
What is done to it
press book
What it sent
[
  {
    method: 'POST',
    url: '/examples/endpoint-request/bookings',
    headers: { authorization: 'Bearer box-office' },
    body: { member: 'm1', seats: 2 },
  },
]
What it then holds
{
  token: 'box-office',
  member: 'm1',
  seats: ['C4', 'C5'],
  note: 'not for the server',
  booking: 'B-2041',
}
What it then says
Booked as B-2041.
Book both seats
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.