Camille lets you define type schemas for your Rails API in Ruby, then generates typed TypeScript request functions from them and typechecks every response at runtime. The front-end and back-end can no longer disagree about the shape of data.
An endpoint defined in Ruby, where data is a controller action,
get :data do
params(
id: Number
)
response(
name: String
)
endbecomes a function in TypeScript:
data(params: {id: number}): Promise<{name: string}>Routes are derived from the schema, so the front-end calls a function instead of remembering HTTP verbs and paths, and Camille makes sure the correct Rails action handles it.
Add this line to your application's Gemfile:
gem 'camille'And then execute:
bundle install
bundle exec rails g camille:installFull documentation is at https://onyxblade.github.io/camille/, covering:
- Schemas and custom types
- Supported type syntax
- TypeScript generation
- Runtime typechecking
- Caching rendered fragments
- Test helper
The docs source lives in docs/; run npm install && npm run dev there to preview locally.
This project uses Semantic Versioning. See CHANGELOG.md.
Run tests with bundle exec rake.
Bug reports and pull requests are welcome on GitHub at https://github.com/onyxblade/camille.