Rabbit Slide Show

REST Rebooted: What Funicular on Rails Carries

2026-12-03

Description

Presentation slide for RubyWorld Conference 2026

Text

Page: 1

REST Rebooted
What Funicular on Rails Carries
hasumikin
RubyWorld Conference 2026
2026-12-03

Page: 2

self.inspect
Hitoshi HASUMI
@hasumikin (GitHub and Twitter)
Creator of PicoRuby
Committer of mruby and mruby/c
Work with ANDPAD, inc.

Page: 3

Today I talk about REST
In 2026?
Yes
Why? At the end

Page: 4

REST: Representational State Transfer
Roy Fielding’s doctoral dissertation, 2000
Start from a system where anything is possible
Add six constraints, and you get a Web that works
1. Client-Server
2. Stateless
3. Cache
4. Uniform Interface
5. Layered System
6. Code on Demand
(optional)
https://ics.uci.edu/~fielding/pubs/dissertation/top.htm

Page: 5

Rails Chose REST 20 years ago
DHH, 2006: “Discovering a World of Resources on Rails”
It’s still the backbone of Rails
(even if your AI agent rewrites your Rails app in Rust)
One line gives you seven routes: resources :posts
GET
/posts
GET
/posts/new
POST
/posts
GET
/posts/:id
GET
/posts/:id/edit
PATCH /posts/:id
DELETE /posts/:id
index
new
create
show
edit
update
destroy

Page: 6

But on the Frontend
The age of the SPA came
We write the Rails resources once more, in JavaScript
URLs, attributes, validations, error handling
“REST is outdated”

Page: 7

Here comes Funicular [フニクラ]
http://picoruby.org/funicular (I’m the author)
An SPA framework that runs on PicoRuby.wasm
PicoRuby.wasm: 10x smaller than CRuby.wasm
Write the frontend in native Ruby, no JavaScript
Tech details in RubyKaigi 2026
🚞
The name means a cable car
Many features such as SSR
React-like Component class,
front-end SQLite3, plugins

Page: 8

[New!] ORM: Object-REST Mapper
maps
because all speak
======================================================================
ActiveRecord
tables
-> Ruby objects
SQL
----------------------------------------------------------------------
Object-REST Mapper
resources -> Ruby objects
REST
One mapper fits every table, because every table speaks
SQL
One mapper fits every resource, if every resource obeys
REST
So, do Rails resources obey the six constraints?

Page: 9

Revisit the Constraints

Page: 10

Constraints 1, 2, 5
1: Client-Server
2: Stateless
5: Layered System
HTTP and Rails have done these all along
Funicular adds nothing

Page: 11

Constraint 3
Cache

Page: 12

The Rails Code You Always Write
# app/controllers/posts_controller.rb
def index
posts = Post.published
render json: posts.map { |post| post_summary(post) } if stale?(posts)
end
stale? returns 304 (Not Modified) when the ETag matches
The browser hears the 304. Does your JavaScript?
Funicular keeps a SQLite3 replica in the browser
It sends If-None-Match. On a 304, the replica answers

Page: 13

Constraint 4
Uniform Interface

Page: 14

The One the SPA Broke
4. Uniform Interface
Rails + HTML
Rails + JSON SPA
=========================================================================
Identify resources by URI
kept
kept
-------------------------------------------------------------------------
Manipulate via representations
kept
kept
-------------------------------------------------------------------------
Self-descriptive messages
kept
*broken*
-------------------------------------------------------------------------
Hypermedia as the Engine of APP State
kept
*broken*
URLs and next actions are hard-coded in the client
What the JSON means is a private agreement
Fielding, 2008: “REST APIs must be hypertext-driven”
https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

Page: 15

Expose Only What You Declare
# app/controllers/api/schema_controller.rb
def comment
render json: Funicular::Schema.build(Comment,
attributes: {
"id"
=> { type: "integer", readonly: true },
"post_id" => { type: "integer", readonly: false },
"body"
=> { type: "string", readonly: false }
})
end
Declare only the attributes to expose
No endpoint is written anywhere

Page: 16

Ruby in the Browser (PicoRuby.wasm)
# app/funicular/models/post.rb
class Post < Funicular::Model
end
# app/funicular/models/comment.rb
class Comment < Funicular::Model
end
# a block receives the result { |result, error| ... }
Post.all
# GET /posts
Post.find(1)
# GET /posts/1
Comment.all(post_id: 1)
# GET /posts/1/comments
Comment.create(post_id: 1, body: "Nice!")
# POST /posts/1/comments
routes.rb becomes the methods in the browser
Note that the classes are empty

Page: 17

Errors Are Uniform Too (demo later)
# server: app/controllers/comments_controller.rb
render json: { errors: comment.errors }, status: :unprocessable_content
# browser
Comment.create(post_id: 1, body: "HELLO") do |comment, error|
patch(errors: error.messages) if error
end
Empty: the browser stops it
(presence comes with the schema)
“HELLO”: the server stops it
(a custom validation stays on the server)
The same errors, in the same place

Page: 18

Constraint 6
Code on Demand

Page: 19

The Forgotten Constraint
The only optional one of the six
A client downloads code and extends what it does
Forgotten? We do it every day: <script src="app.js">
But what arrives is another language, another model

Page: 20

The True Face of Code on Demand
The server delivers a client that can talk to it
The same language
The same models
The same validations

Page: 21

What Funicular on Rails Carries
Rails ─────────────────────────────────────> Browser
picoruby.wasm
app.mrb
schema (JSON)
the Ruby interpreter itself
your components and models
attributes, validations, endpoints, associations
Validations and associations derive from ActiveRecord
The same component also renders on the server (SSR)

Page: 22

Demo : /blog
👀 Browser: /blog → /blog/1 → back to /blog (304)
→ /blog/1 → comment “(blank)” and “HELLO”

Page: 23

Recap
REST Constraint
The Rails code you always write
=============================================================
1. Client-Server
2. Stateless
(HTTP and Rails)
5. Layered System
-------------------------------------------------------------
3. Cache
stale?(posts)
-------------------------------------------------------------
4. Uniform Interface
resources :posts
belongs_to :post
render json: { errors: record.errors }
-------------------------------------------------------------
6. Code on Demand
PicoRuby.wasm + app/funicular/**/*.rb

Page: 24

Funicular and Hotwire
Hotwire
Funicular
==================================================================
Stays on
Rails + HTML
Rails + SPA
------------------------------------------------------------------
3. Cache
HTTP cache
replica + ETag
------------------------------------------------------------------
4. Hypermedia
links and forms
schema (not strict)
------------------------------------------------------------------
6. Code on Demand
JavaScript
Ruby, same models
------------------------------------------------------------------
Client-side data
little
rows and queries
Hotwire keeps REST by staying with HTML
Funicular brings REST back to the SPA
The same belief: REST on Rails is right

Page: 25

Why REST, Now?

Page: 26

The Age of AI
With AI, anything is possible again
Anyone can build anything
Anyone can attack anything
The second one is the serious one
Fielding started from there, and added constraints

Page: 27

Every Hand-Made API Is a Door
An AI reads your JS bundle and finds every endpoint
It tries every one of them, all night, for almost nothing
A hand-made API has hand-made checks
A hand-made check is where the hole is

Page: 28

Stay on the Rails with Funicular
REST gives every resource the same shape
Stateless: each request proves who it is
Uniform Interface: every message can be inspected in the same
way
The server has the last word on validations
Expose only what you declare: user_id never leaves the
server
Predictable for you, your reviewer, and your AI agent

Page: 29

REST Did Not Get Old
It ran on the Rails side only
A funicular climbs only when two cars share one cable

Page: 30

A New Journey for Rails and REST
https://picoruby.org/funicular
https://github.com/picoruby/funicular
https://github.com/hasumikin/funicular-demo

Page: 31

Appendix

Page: 32


        

Page: 33

Associations Travel Too
# in the browser
comment.post
post.comments
comment.user
# Post.local.find_by(id: comment.post_id)
# Comment.local.where(post_id: post.id)
# NoMethodError: user_id is not exposed
Nothing is declared in the browser
post_id is exposed, so it travels. user_id is not

Page: 34

When You Want Off the Convention
# post "login",
to: "sessions#create"
# get "current_user", to: "sessions#show"
def session_schema
render json: Funicular::Schema.build(nil,
attributes: { ... },
controller: "sessions",
endpoints: { "current" => "sessions#show" })
end
Convention over Configuration
With a way out, as Rails always has
# name the controller
# alias a route

Page: 35

Is It HATEOAS?
A REST API should be entered with no prior knowledge
beyond the initial URI (bookmark) and set of
standardized media types …
The transitions may be determined (or limited by) the
client’s knowledge of media types and resource
communication mechanisms, both of which may be
improved on-the-fly (e.g., code-on-demand).
Not in the strict sense: no links in each response
But no URL is hard-coded in the client
The server delivers the client and the schema on every

Page: 36

Not There Yet
Optimistic updates — a write waits for the server
Automatic refresh — only an explicit fetch for now

Other slides