Bindings
Edit on GitHubThe binding module allows you to write backend logic (route files) in other programming languages than JavaScript. Primate will then compile your non-JavaScript routes to WASM, and run them as WebAssembly.
As a general rule, Primate endeavors to offer the same or a similar API in other
programming languages as concerns the request object that is passed to and
the handlers (view
, redirect
) that are available to JavaScript routes.
The @primate/binding
module currently supports TypeScript, Go, Python and
Ruby.
Install
npm install @primate/binding
The individual programming languages are available as individual exports.
Support matrix
Feature | JS, TS | GO | Python | Ruby |
---|---|---|---|---|
serving strings | ✓ | ✓ | ✓ | ✓ |
serving objects | ✓ | ✓ | ✓ | ✓ |
serving streams | ✓ | ✗ | ✗ | ✗ |
redirect handler |
✓ | ✓ | ✓ | ✓ |
view handler |
✓ | ✓ | ✓ | ✓ |
error handler |
✓ | ✗ | ✓ | ✓ |
request.body |
✓ | ✓ | ✓ | ✓ |
request.path |
✓ | ✓ | ✓ | ✓ |
request.query |
✓ | ✓ | ✓ | ✓ |
request.cookies |
✓ | ✓ | ✓ | ✓ |
request.headers |
✓ | ✓ | ✓ | ✓ |
request.session |
✓ | ✓ | ✓ | ✓ |
request.store.* |
✓ | ✗ | ✓ | ✗ |
Type conversions
Whenever you define and use runtime types, the request object will be augmented with dispatchers to coerce the input string into a given type. In the following is a table with the supported base types and what types they are converted to in every supported language.
Type | JS | GO | Ruby |
---|---|---|---|
boolean | boolean | bool | |
i8 | number | int8 | Integer |
i16 | number | int16 | Integer |
i32 | number | int32 | Integer |
i64 | bigint | int64 | Integer |
f32 | number | float32 | Float |
f64 | number | float64 | Float |
u8 | number | uint8 | Integer |
u16 | number | uint16 | Integer |
u32 | number | uint32 | Integer |
u64 | bigint | uint64 | Integer |
string | string | string | String |