Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Basejump
Search
Ryan Paul
March 14, 2016
Programming
1
1.3k
Introduction to Basejump
Build REST APIs on RethinkDB without writing code
Ryan Paul
March 14, 2016
Tweet
Share
More Decks by Ryan Paul
See All by Ryan Paul
Using Async Iterators in Node.js
segphault
0
970
Realtime data visualization with RethinkDB and Epoch
segphault
1
690
Realtime web apps with RethinkDB and full-stack Ruby
segphault
2
310
Jupyter and RethinkDB
segphault
1
670
Using RethinkDB with Tornado & EventMachine
segphault
0
640
RethinkDB Training Course
segphault
3
410
RethinkDB Cluster Monitoring
segphault
0
700
Composing frontend Web applications with MontageJS
segphault
4
1.4k
Intro to MontageJS
segphault
1
190
Other Decks in Programming
See All in Programming
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
950
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
8
730
EventSourcingの理想と現実
wenas
5
2k
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
2.9k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
4
13k
ActiveRecordの力でDBのメタデータを迅速に解析する
lnit
5
2.2k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
4
150
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
10
2.2k
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.1k
Java ジェネリクス入門 2024
nagise
0
530
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
350
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
Teambox: Starting and Learning
jrom
132
8.7k
Facilitating Awesome Meetings
lara
49
6k
How to Ace a Technical Interview
jacobian
275
23k
How STYLIGHT went responsive
nonsquared
95
5.1k
GraphQLとの向き合い方2022年版
quramy
43
13k
It's Worth the Effort
3n
183
27k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
360
Raft: Consensus for Rubyists
vanstee
136
6.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Transcript
Basejump Build a REST API on RethinkDB
Ryan Paul RethinkDB Evangelist @segphault
API Anatomy Dissecting an API backend
API Anatomy • Server to parse & handle requests •
Routing to manage endpoints • Validation to sanitize user input • Persistence to store & retrieve data
API Anatomy RethinkDB NodeJS JOI Koa Vue Browser REST API
Koa Router W3C Fetch Real-world RethinkDB stack
API Anatomy Persistence Runtime Validation Server Frontend Framework Browser REST
API Router REST Client Real-world RethinkDB stack
API Anatomy • Lots of layers between persistence and requests
• More boilerplate than business logic • Repetitive code that is difficult to reuse
API Anatomy router.post("/api/event/:id/messages", function*(id) { this.checkBody("message").notEmpty(); if (this.errors) this.throw(400, {success:
false, errors: this.errors}); yield r.table("messages").insert({ created: r.now(), text: this.request.body.message, sender: sender, event: id}); this.body = {success: true}; });
Can we abstract away the boilerplate?
Project Basejump Attach queries to endpoints
Basejump • Visual tool for prototyping API backends • Dynamic
routing middleware for attaching queries to endpoints • Powered by declarative JSON description format
Basejump
{A} 1ST
Basejump Router • Database agnostic routing middleware • Uses Node’s
VM module to execute code • Integrates seamlessly with Koa and Socket.io • Swagger-based format to describe routes and actions
Swagger
Swagger • Standard format for describing APIs — can use
YAML or JSON • Uses JSON Schema for validation • Supported by many tools & frameworks • Extensible via vendor properties
Swagger paths: /test: get: parameters: - {in: query, name: count,
type: number} x-action: > r.table("test") .orderBy(r.desc("time")) .limit(params.count) post: parameters: - in: body name: body schema: $ref: "#/definitions/test" x-action: > r.table("test").insert(params.body)
Embed Basejump • Embed in your own Node app •
Pass custom objects into the execution context • Inherit and override the request handler • Custom pre & post processing on input and output
Embed Basejump const app = require("koa")(); const router = require("basejump-router");
const r = require("rethinkdbdash")(); app.use(require("kcors")()); app.use(require("koa-bodyparser")()); app.use(router.middleware.koa({ swagger: "routes.yaml", context: {r: r} })); app.listen(8000);
Project Basejump Status & Future Plans
Basejump • Not ready for adoption quite yet • API
and data format still subject to change • New features might necessitate additional format churn
Feature Roadmap • Support for embedding in Express • Interactive
Schema editing • Pluggable view system • Route collections and blueprints • Authentication and user management • Live API debugging
Feature Ideas • Generate client libraries for mobile & web
• Use schemas to generate input forms & data dashboard • Support for file uploads & multipart mime • Automatically generate tables and indexes from schemas
How does it compare to Fusion?
How does it compare to Fusion? Horizon?
Basejump vs Horizon • Basejump: backend-first development & REST APIs
• Horizon: frontend-first development & WebSockets
Basejump & Horizon • Embed Basejump and Horizon middleware in
the same Node app • Expose Basejump routes through Horizon custom endpoint • Converge authentication and schema validation?
• RethinkDB website: http://rethinkdb.com • Basejump Router: http://github.com/segphault/ basejump-router •
Follow me on Twitter: @segphault Resources