Slide 1

Slide 1 text

Web-APIs mit Node.js und TypeScript für .NET-Entwickler BASTA! Spring 2017 Manuel Rauber @manuelrauber | [email protected] Software Architect

Slide 2

Slide 2 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Manuel Rauber Software Architect @ Thinktecture AG ! [email protected] " @manuelrauber # https://manuel-rauber.com Microsoft MVP The guy who’s talkin’

Slide 3

Slide 3 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Web APIs Node.js TypeScript Restify Token Authentication Database Examples Talking Points

Slide 4

Slide 4 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Overview Web APIs

Slide 5

Slide 5 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Overview • REST APIs, HTTP APIs, “whatever APIs” • Use case oriented: model functional services with dedicated interfaces • Can use several other services for data aggregation • Secured by tokens • Consumable by every HTTP(S) speaking client • Can involve WebSocket for real-time communication Web APIs HTTP HTTPS WebSocket Service A Service B Service C Web APIs (ASP.NET, Node.js, …) HTML5-Application (Single-Page Application) Web Cordova Electron

Slide 6

Slide 6 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Node.js is not jQuery in cool ;-) Node.js

Slide 7

Slide 7 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Intro • Server-side JavaScript powered by Chrome’s V8 JavaScript engine • Asynchronous, event-driven I/O API • Package management via Node Package Manager (npm) or Yarn • Cross platform: Linux, macOS, Windows • Upcoming: Alternative runtime powered by Microsoft’s ChakraCore Node.js

Slide 8

Slide 8 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Features • ECMAScript 6 • Experimental ECMAScript 7 • http://node.green/ • Classes • Typed arrays • Fat Arrow/Lambda Expression • Templated Strings Node.js

Slide 9

Slide 9 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Node.js ASP.NET Core JavaScript, TypeScript, CoffeeScript, … C# Node Package Manager, Yarn NuGet Dynamic types Static types Single threaded event loop (but async I/O threads) Multi threaded Node.js & ASP.NET Core

Slide 10

Slide 10 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Server Architecture Node.js

Slide 11

Slide 11 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Pros • Full stack JS’ish development • Universal JavaScript: Share code for client & server • Open Source loving community • Enterprise proven: Netflix, Paypal, Groupon, Walmart, … Node.js https://nodejs.org/static/documents/casestudies/Node_CaseStudy_Nasa_FNL.pdf

Slide 12

Slide 12 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Watch out! • Single threaded Event Loop: Avoid heavy CPU usage • Utilizes one CPU only: Scale via clustering • Relational databases can be strange • Code is (often the only) documentation Node.js

Slide 13

Slide 13 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 • Designed by Anders Hejlberg, who also designed C# • Typed superset of JavaScript that transpiles to plain JavaScript • Types are optional, but useful metadata for tooling • Static Code Analysis • Linting • IntelliSense TypeScript

Slide 14

Slide 14 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Overview • Node.js module to build Web APIs • Middleware support • Client & Server components • Routing Restify Middleware 1 // Server logic next() // more logic Middleware 2 // Server logic next() // more logic Middleware 3 // Server logic // more logic Request Response Client Logging Authentication …

Slide 15

Slide 15 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Overview • Securing resources (APIs): Authentication & Authorization • OAuth 2 Protocol: Simple & standard method for web, mobile and desktop applications • OpenID Connect: Identity Layer on top of OAuth 2 Token Authentication

Slide 16

Slide 16 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Node.js • Several node packages passport, oauth2-server, oauth2orize, OpenIdConnect, node-oauth2-provider, jwt-simple • Currently no state-of-the-art package: Leverage third-party applications like IdentityServer • Implementation depends on the used package Token Authentication

Slide 17

Slide 17 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 Overview • Adapters for a lot of databases • NoSQL databases MongoDB, CouchDB, … • Relational databases MSSQL, PostgreSQL, MySQL, SQLite, ... • SequelizeJS as an ORM Multiple databases, transactions, migrations, replication, query API Databases

Slide 18

Slide 18 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 DEMO

Slide 19

Slide 19 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 • Node.js overview Feature support, Node.js server, pros, watch outs • Web APIs with restify Routing, middlewares • Token Authentication via OAuth 2 • Relational databases via SequelizeJS Models, query API Summary

Slide 20

Slide 20 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 eBook Die Serverwelt von Node.js https://entwickler.de/press/shortcuts/die-serverwelt-von-node-js-2-262553.html

Slide 21

Slide 21 text

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler BASTA! Spring 2017 • Node.js: https://nodejs.org/ • Node.js at Paypal: https://www.paypal-engineering.com/tag/node-js/ • Node.js at Netflix: http://techblog.netflix.com/search/label/node.js • Node.js at scale: http://venturebeat.com/2012/01/24/node-at-google-mozilla-yahoo/ • Restify: http://restify.com/ • SequelizeJS: http://sequelizejs.com/ • Node.js eBook “Die Serverwelt von Node.js”: https://entwickler.de/press/shortcuts/die- serverwelt-von-node-js-2-262553.html Resources

Slide 22

Slide 22 text

Thank you! Questions? Repository https://github.com/thinktecture/basta-spring-2017-nodejs-typescript-demo Contact @manuelrauber [email protected]