JS20

Documentation

JS20 - Documentation

Route parameters

Pass along route params like you'd expect from express - :[variableName]. When you put a route param in the path, and a corresponding property in your input schema, is it automatically converted from a route param and passed along in your input object.

app.addEndpoint({
    path: '/cars/:id',
    method: 'PUT',
    inputSchema: {
        ...sCar,
        id: sString().type(),
    },
    outputSchema: Schema.withInstance(sCar),
    isLoggedIn: true,
    run: async (system, input) => {
        // Id is passed along in input. Input is now Car & { id: string }
        return system.models.car.updateById(input.id, input);
    }
});
JS20