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.
{
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' }],
},
],
}{
POST /examples/endpoint-request/bookings: { status: 200, body: { id: 'B-2041', seats: 2 } },
}press book
[
{
method: 'POST',
url: '/examples/endpoint-request/bookings',
headers: { authorization: 'Bearer box-office' },
body: { member: 'm1', seats: 2 },
},
]{
token: 'box-office',
member: 'm1',
seats: ['C4', 'C5'],
note: 'not for the server',
booking: 'B-2041',
}Booked as B-2041. Book both seats
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.