API shorthand syntax
By KajMagnus @KajMagnus2021-05-22 18:17:19.765Z2021-05-22 19:32:17.601Z
Shorthand
In the API docs, this:
POST /-/v0/something {
field: 'value',
oneTwoMany: 123,
}
means sending a HTTP POST request to /-/v0/something
with a header Content-Type: application/json
and a JSON payload: { "field": "value", "oneTwoMany": 123 }
.
Typescript
This:
POST /-/v0/add-turtles {
turtles: Turtle[],
}
interface Turtle {
name: St,
isCute?: Bo,
isKind: Bo,
speedMps: Nr,
}
is suddenly Typescript. []
means array. St
, Bo
and Nr
mean string, boolean and number. The question mark in isCute?
means that that field is optional.
The above add-turtles
endpoint could thus be called like so:
POST /-/v0/add-turtles {
turtles: [{
name: "Bowser",
isKind: false,
speedMps: 5,
}, {
name: "Morla",
isCute: true, <—— optional field
isKind: true,
speedMps: 0,
}]
}
Linked from: