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.2k
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
870
Realtime data visualization with RethinkDB and Epoch
segphault
1
630
Realtime web apps with RethinkDB and full-stack Ruby
segphault
2
280
Jupyter and RethinkDB
segphault
1
600
Using RethinkDB with Tornado & EventMachine
segphault
0
580
RethinkDB Training Course
segphault
3
390
RethinkDB Cluster Monitoring
segphault
0
590
Composing frontend Web applications with MontageJS
segphault
4
1.3k
Intro to MontageJS
segphault
1
180
Other Decks in Programming
See All in Programming
『データ可視化学入門』をPythonからRに翻訳した話(増強版)
bob3bob3
0
280
So You Think You Know Git - Part 2
schacon
PRO
0
1.3k
Deep Dive 大規模システムアーキテクチャ/開発組織エンジニアリング / Deep Dive Large-Scale System Architecture, Development Organization Engineering
nrslib
5
440
品質が高いコードって何?Rev2.1
ickx
1
390
Reckoner の Scala プロジェクトにおける オブザーバビリティの取り組み / Observability Initiatives in Reckoner's Scala Project
nomadblacky
0
820
MySQL のインデックスの種類をおさらいしよう! / overviewing indexes in MySQL
okashoi
0
160
Next.js で SPA を構築する際の辛み
hayatow
0
220
Honoとhtmx
yusukebe
6
1.1k
Cloudflare Workersの環境を再現することについて
yusukebe
5
730
TDDと今まで
kanayannet
0
110
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
1
110
期限が近づいてきた!Privacy Manifests対応
ryunakayama
5
3.1k
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Mobile First: as difficult as doing things right
swwweet
215
8.5k
It's Worth the Effort
3n
180
27k
Art, The Web, and Tiny UX
lynnandtonic
288
19k
The Brand Is Dead. Long Live the Brand.
mthomps
48
20k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
153
14k
Thoughts on Productivity
jonyablonski
57
3.7k
GraphQLの誤解/rethinking-graphql
sonatard
48
9.1k
Bash Introduction
62gerente
604
210k
The Invisible Side of Design
smashingmag
293
49k
Atom: Resistance is Futile
akmur
258
25k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
67
38k
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