Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Introduction to Basejump
Ryan Paul
March 14, 2016
Programming
1
1k
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
720
Realtime data visualization with RethinkDB and Epoch
segphault
1
580
Realtime web apps with RethinkDB and full-stack Ruby
segphault
2
270
Jupyter and RethinkDB
segphault
1
470
Using RethinkDB with Tornado & EventMachine
segphault
0
470
RethinkDB Training Course
segphault
3
360
RethinkDB Cluster Monitoring
segphault
0
420
Composing frontend Web applications with MontageJS
segphault
4
1k
Intro to MontageJS
segphault
1
170
Other Decks in Programming
See All in Programming
Rust、何もわからない...#3
estie
0
150
How to Test Your Compose UI (Droidcon Berlin 2022)
stewemetal
1
130
10歳の minne から、これから長く続くプロダクトを作るすべての人へ
tsumichan
9
3.6k
読みやすいコード クラスメソッド 2022 年度新卒研修
januswel
0
2.9k
それ全部エラーメッセージに書いてあるよ!〜独学でPHPプログラミングが上達するたった一つの方法〜
77web
1
150
プロダクトのタイプ別 GraphQL クライアントの選び方
shozawa
0
8.2k
Windows コンテナ Dojo 第5回 OpenShift で学ぶ Kubernetes 入門
oniak3ibm
PRO
0
130
ECサイトの脆弱性診断をいい感じにやりたい/OWASPKansaiNight_LT1_220727
owaspkansai
0
290
「混ぜるな危険」を推進する設計
minodriven
8
2.5k
Amazon Lookout for Visionで 筆跡鑑定してみた
cmnakamurashogo
0
160
Introduction to Property-Based Testing @ COSCUP 2022
cybai
1
150
kintoneでランダム取得を作ってみた(imoniCamp 2022-07-27)
shokun1108
0
140
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
106
5.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
655
120k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
224
49k
Thoughts on Productivity
jonyablonski
44
2.4k
In The Pink: A Labor of Love
frogandcode
131
21k
Optimizing for Happiness
mojombo
365
64k
BBQ
matthewcrist
74
7.9k
Product Roadmaps are Hard
iamctodd
35
6.8k
Robots, Beer and Maslow
schacon
152
7.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
351
21k
What's in a price? How to price your products and services
michaelherold
229
9.4k
The Invisible Side of Design
smashingmag
290
48k
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