The 2nd version of my talk on the Future of Rails. A more streamlined version.
Mentor / Author / Developer
View Slide
FUTURE PREDICTIONSARE OFTEN WRONG
ISN’T RAILSTHE FUTURE OF RAILSAS YOU KNOW IT TODAY
TO KNOW THE FUTURELOOK TO THE PAST
APIs
APPLICATIONPROGRAMMINGINTERFACE
APIsARE HOW PROGRAMSTALK TO EACH OTHER
Your AppAPIThirdPartyApp
APIsARE AN AGREED CONTRACT
Your AppThirdPartyAppAPI“Can you give me dataabout employees?”
API“Sure, here’s my data”ThirdPartyAppYour App
SOAP
“Please send me all youremployee data”In the past…(1998)SOAP APIs
encoding='UTF-8'?>In the past…(1998)SOAP APIs
--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Type: text/xml--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Id:Content-Type: application/octet-streamContent-Transfer-Encoding: binary"User/Employee ID","First Name","Employment Details HireDate","Username","Division","CompanyCountry","Location","Department","CostCenter","Team","Supervisor","Manager User Sys ID","ContractType","Gender"--uuid:1fe211a2-9207-4981-b1ba-95c51dc9dadd--In the past…(1998)SOAP APIs
--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Type: text/xml--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Id:Content-Type: application/octet-streamContent-Transfer-Encoding: binary"User/Employee ID","First Name","Employment Details HireDate","Username","Division","CompanyCountry","Location","Department","CostCenter","Team","Supervisor","Manager User Sys ID","ContractType","Gender"--uuid:1fe211a2-9207-4981-b1ba-95c51dc9dadd--SOAP APIs In the past…(1998)
SOAPSIMPLE
Retrieved: Tuesday, 8th May,2018.--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Type: text/xml--uuid:1fe211a2-9207-4981-b1ba-95c51dc9daddContent-Id:Content-Type: application/octet-streamContent-Transfer-Encoding: binary"User/Employee ID","First Name","Employment Details HireDate","Username","Division","CompanyCountry","Location","Department","CostCenter","Team","Supervisor","Manager User Sys ID","ContractType","Gender"--uuid:1fe211a2-9207-4981-b1ba-95c51dc9dadd--
SOAPIS NOT A GOOD API
Q: “DO YOUKNOW SOAP?”A: NOPE NOPE NOP
JSONIS GOOD
[{"User/Employee ID": "ryan001","First Name": "Ryan","Username": "ryanbigg",. . .}. . .]And then…(circa 2001)
JSONJAVASCRIPT
JSONThirdPartyAppYour App“Can you give me dataabout employees?”
JSON“Sure, here’s my data”ThirdPartyAppYour App[{"User/Employee ID": "ryan001","First Name": "Ryan","Username": "ryanbigg",. . .}. . .]
HAPPENEDTHEN RAILSHAPPENED
A browserJavaScript,CSS,Images,and RailsTheMonolithAnd thenand then(circa 2011)DatabaseMakes your applook greatMakes your appdo stuff
A browserReact AppFrontendAppBackendAppNow…(2018)TheDuolithDatabaseRails App
A browserReact AppFrontendAppBackendAppNow…(2018)DatabaseRails AppMakes your applook greatMakes your appdo stuff
A browserReact AppFrontendAppBackendAppNow…(2018)DatabaseRails AppSeparaEonofConcerns
Rails AppsIn the past
Rails AppsNow
A browserReact AppFrontendAppBackendAppTheDuolithDatabaseRails AppNow…(2018)
A browserFrontendAppBackendApp“Views”, CSS, JS, etc.Controllers, models, etc.React AppDatabaseRails AppNow…(2018)
HOWDOTHESETHINGS TALK?A browserReact App???DatabaseRails App
APIsARE HOW PROGRAMSTALK TO EACH OTHERSlide #7:
A browserReact AppJSON APIRecently…DatabaseRails App
A browserReact App “Show me a post”Recently…DatabaseRails App
A browserReact App“Okay, here’sthe post”Recently…DatabaseRails App
JSON APIsPOSTCOMMENT #1COMMENT #2GET /api/posts/1GET /api/posts/1/comments
GET /api/posts/1{"id": 1,"title": "Hello World","body": "This is my blog's first post.""author": "Ryan Bigg"}JSON APIs
GET /api/posts/1/comments[{text: "Great first post!",by: "Totally not Ryan"},...]JSON APIs
A browserReact App/api/posts/:id/api/comments…Currently…JSON APIsNeed to build lots of these…DatabaseRails App/api/posts
EVERYONEDOES THIS
EVENFACEBOOK
WELL…THEY DID
GET /api/posts/1{"id": 1,"title": "Hello World","body": "This is my blog's first post.""author": "Ryan Bigg"}JSON APIs Problem #1
GET /api/posts/1{"id": 1,"title": "Hello World","body": "This is my blog's first post.""author": "Ryan Bigg”,“comments”: [{“id”: 1,...}]}JSON APIs Problem #2
FacebookiOS AppFacebookServers1. Get news feed items2. Here are your items3. Get comments4. Here are the comments5. Fetch user data6. Here are the users
JSONIS GOODBUT WE CAN DO BETTER
/graphqlNow(and the future)Only oneendpoint(born 2012)DatabaseRails AppA browserReact App
Fetching a Postquery postQuery {post(id: 1) {idtitlebodyauthor}}{"data": {"post": {"id": 1,"title": "Hello World","body": "First post!”,"author": "Ryan Bigg",}}}Query ResponseGRAPHQL
query postQuery {post(id: 1) {idtitlebodyauthor}}{"data": {"post": {"id": 1,"title": "Hello World","author": "Ryan Bigg",}}}Query ResponseGRAPHQL Ignoring a field
Post + Commentsquery postQuery {post(id: 1) {idtitlebodyauthorcomments {textby}}}{"data": {"post": {"id": 1,"title": "Hello World","body": "First post!”,"author": "Ryan Bigg","comments": [{text: "Great first post!",by: "Totally not Ryan"},...]}}}Query ResponseGRAPHQL
GRAPHQLPOSTCOMMENT #1COMMENT #2POST /graphql
query postQuery {...}query commentQuery {comment(id: 1) {textuser}}{"data": {“post”: {...},“comment”: {text: "Great first post!",user: "Totally not Ryan”}}}Query ResponseGRAPHQL Two queriesat the same Eme
FacebookiOS AppFacebookServers1. Get news feed items,their comments andtheir users2. Here’s everything
GRAPHQLIS BEST
The future…A browserReact AppFrontendAppBackendAppDatabaseRails App
✉: [email protected]Thanks!: @ryanbigg▶: hIp://bit.ly/radar-for
hIps://developer.github.com/v3/API ExamplesREST + JSONhIps://developer.github.com/v4/GRAPHQL
hIps://www.howtographql.com/Learn these:GraphQLhIps://reactjs.org/tutorial/tutorial.htmlReact
hIps://www.sandimetz.com/99boIles/Read these:99 BOTTLEShIps://www.poodr.comPRACTICAL OBJECT-ORIENTED DESIGN IN RUBY
hIps://bit.ly/exploding-rails-talkhIps://speakerdeck.com/radar/exploding-railshIps://leanpub.com/exploding-railsExploding RailshIps://github.com/radar/twist-v2MY EXAMPLE APPLICATION