Download - Reinventing Web APIs with Falcor.NET
![Page 1: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/1.jpg)
Craig Smitham@craigsmitham
https://github.com/falcordotnet/falcor.net
FALCOR@NetflixUIE@falcorjs
![Page 2: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/2.jpg)
Today• The (d)evolution REST at Netflix• Falcor• JSON Graph• Building .NET APIs with Falcor• Status and Next Steps
![Page 3: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/3.jpg)
REST
![Page 4: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/4.jpg)
The World Wide Web• Graph of Resources (WWW)• Each Resource has a Unique Identifier
(URL)• VERBs for transforming resource state
– GET– PUT– POST– DELETE
![Page 5: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/5.jpg)
is a browsing problem.
![Page 6: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/6.jpg)
http://www.netflix.com/genreLists?rowOffset=0&rowSize=5&colOffset=5&colSize=15&titleprops=name,boxshothttp://www.netflix.com/setRating?titleId=5&view=movieDetailPage
REST-less API
20101
Netflix’s RESTful APIhttp://www.netflix.com/genreList/12429
http://www.netflix.com/title/1601923
![Page 7: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/7.jpg)
Title Resourcehttp://netflix.com/titles/95632123
{ id: 2523, name: “House of Cards”, boxshot: “http://…/018-192-x50.png”, rating: 5, bookmark: 52119562, director: “David Fincher”, // a few more fields}
![Page 8: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/8.jpg)
REST Latency01: GET /genreLists02: GET netflix.com/titles/95632503: GET cdn01.netflix.com/072-192-x50.png04: GET netflix.com/titles/99233805: GET cdn03.netflix.com/018-192-x50.png06: GET netflix.com/titles/91273807: GET cdn09.netflix.com/651-70x50.png …27: GET netflix.com/titles/56182628: GET cdn23.netflix.com/018-70x50.png
![Page 9: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/9.jpg)
Once the web was a place to get things.
![Page 10: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/10.jpg)
Today the web is a place to do things.
![Page 11: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/11.jpg)
Web Server Application Server
Web Pages serve small amounts of large resources.Web Apps serve large amounts of small resources.
![Page 12: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/12.jpg)
http://www.netflix.com/genreLists?rowOffset=0&rowSize=5&colOffset=5&colSize=15&titleprops=name,boxshothttp://www.netflix.com/setRating?titleId=5&view=movieDetailPage
REST-less API
20101
Netflix’s RESTful APIhttp://www.netflix.com/genreList/12429
http://www.netflix.com/title/1601923
![Page 13: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/13.jpg)
RPC
![Page 14: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/14.jpg)
/genreList?pageSize=13x15 /search?text=house/genreList?pageSize=13x15 /search?text=netflix/titleDetails?id=342/titleDetails?id=342
RPC
![Page 15: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/15.jpg)
RPC: No Cache Consistency
Title
Title
Title
PersonalizedGenre Lists
/genreLists ?page=4x4 &props=name,title
/getTitleDetails?id=3432
Same info, two different URLS!
![Page 16: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/16.jpg)
REST
• Cache Consistency• Loose Coupling
RPC
• Small Message Sizes• Low Latency
?
![Page 17: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/17.jpg)
FALCOR
![Page 18: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/18.jpg)
What is Falcor?
![Page 19: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/19.jpg)
Falcor is not a replacement for your Database, MVC framework,
or your Web Server.
![Page 20: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/20.jpg)
Falcor fits into your existing stack,allowing the layers to
communicate more efficiently.
![Page 21: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/21.jpg)
/model.json
![Page 22: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/22.jpg)
An Async Model
![Page 23: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/23.jpg)
/member.json/member.json?...
![Page 24: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/24.jpg)
FALCORon
![Page 25: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/25.jpg)
![Page 26: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/26.jpg)
Live Coding a mini-Netflixwith Falcor
![Page 27: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/27.jpg)
Netflix’s Domain Model is a Graph
![Page 28: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/28.jpg)
JSON is for Trees.
![Page 29: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/29.jpg)
“Suggestions for You”
“New Releases”
Genre Lists
id:956
id:956
![Page 30: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/30.jpg)
Introducing JSON Graph
![Page 31: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/31.jpg)
Building a Routed Model
/member.json
genres titlesratings
![Page 32: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/32.jpg)
Falcor on the Server• Caching benefits of REST• Low-latency/Small message size of
RPC• Supports Function Calls
![Page 33: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/33.jpg)
/member.json/member.json?path=titlesById[2344][“name”, “description”…”staffing”]
Show Detail Controller
<html></html>Show Detail View<div>{{ title.getValue(“name”)|async}}
{{ title.getValue(“description”)|async}} … {{ title.getValue(“staffing”)|async}}</div>
Related Titles
![Page 34: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/34.jpg)
Falcor for .NET• Early alpha available now• https://
github.com/falcordotnet/falcor.net• OWIN middleware
– ASP.NET 5 support coming soon• Help and contributions from:
– Jafar Husain, Netflix– Pavel Vasek
![Page 35: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/35.jpg)
Falcor.NET Router
public class NetflixRouter : FalcorRouter { public NetflixRouter(..., int userId) { Get["titlesById[{ranges:titleIds}]['rating']"] = async parameters => { List<int> titleIds = parameters.titleIds; var ratings = await ratingService.GetRatingsAsync(titleIds, userId); var results = titleIds.Select(titleId => { var rating = ratings.SingleOrDefault(r => r.TitleId == titleId); var path = Path("titlesById", titleId); if (rating == null) return path.Keys("userRating", "rating").Undefined(); if (rating.Error) return path.Keys("userRating", "rating").Error(rating.ErrorMessage); return path .Key("userRating").Atom(rating.UserRating) .Key("rating").Atom(rating.Rating); });
return Complete(results); };
Get["genrelist.mylist"] = async _ => { ... }; } }
![Page 36: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/36.jpg)
OWIN Middleware (WIP)
public class Startup { public void Configuration(IAppBuilder app) { app.UseFalcor("/model.json", routerFactory: config => new NetflixRouter(...));
... } }
![Page 37: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/37.jpg)
Bind to the Cloudvar model = new falcor.Model({ source: new falcor.HttpDataSource('/model.json')});
model.get('titlesById[2..5]["rating", "userRating"]') .then(logJson, logJsonError);
// Set up our model
// Query model asynchronously
// Handle results ...
![Page 38: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/38.jpg)
When Should I Use Falcor?
Good Fit Poor Fit
Fetching large amounts of small resources (e.g. web components, JSON, metadata, etc.)
Fetching small amounts of large resources(e.g. web pages, images, files, etc.)
Aggregating heterogeneous services efficiently (e.g. microservices or loosley-coupled modules)
Fetching from a single back-end data source or service
Delivering responsive and capable end-user client experiences Systems integration and public APIs
Heterogeneous and evolving data access patterns (multiple devices, changing use cases)
Static websites
Consider the Falcor approach when you are developing a client/server architecture provides a rich data-driven interactive user experience.
![Page 39: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/39.jpg)
Next Steps• Implement Set, Call• Support batchable service requests• Composable/distributed routers• Performance testing• Documentation• 1.0 milestone – Early 2016• Contributors welcome!
![Page 40: Reinventing Web APIs with Falcor.NET](https://reader031.vdocuments.us/reader031/viewer/2022030121/58a207251a28ab40098b506f/html5/thumbnails/40.jpg)
How to Get Involved• GitHub repository: https://
github.com/falcordotnet/falcor.net• Gitter Chat: https://
gitter.im/falcordotnet/falcor.net• Learning Resources: https://
github.com/falcordotnet/falcor.net/wiki/Learning-Resources