Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler

Web-APIs mit Node.js und TypeScript – für .NET-Entwickler

Full-Stack TypeScript: Im Frontend werkeln moderne Single-Page-Application-Frameworks wie Angular 2, während im Hintergrund leichtgewichtige Web-APIs zur Kommunikation arbeiten. Dank Node.js sprechen beide Welten eine gemeinsame Sprache: TypeScript – ein um Typen angereichertes Superset von JavaScript. Lassen Sie uns gemeinsam einen Blick in die Node.js-Welt mit TypeScript werfen und dabei Aspekte von modernen Web-APIs – wie die Anbindung von Datenbanken oder der Echtzeitkommunikation – beleuchten. Mit wenigen Zeilen Code schafft Manuel Rauber von Thinktecture eine Grundlage für Ihr „Next Generation“-Web-API.

Manuel Rauber

February 22, 2017
Tweet

More Decks by Manuel Rauber

Other Decks in Programming

Transcript

  1. 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’
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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 …
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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