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

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

Manuel Rauber
September 28, 2017

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

Full-Stack TypeScript: Im Frontend werkeln moderne Single-Page-Application-Frameworks wie Angular, 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. Ob async/await, Klassen, Eigenschaften oder Generics – all das ist mit TypeScript möglich. 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 die Echtzeitkommunikation – beleuchten. Mit wenigen Zeilen Code schafft Manuel Rauber von Thinktecture eine Grundlage für Ihr „Next Generation“ Web-API.

GitHub: https://github.com/thinktecture/basta-herbst-2017-nodejs-typescript

Manuel Rauber

September 28, 2017
Tweet

More Decks by Manuel Rauber

Other Decks in Programming

Transcript

  1. Consultant @ Thinktecture AG ! [email protected] " @manuelrauber # https://manuel-rauber.com

    Microsoft MVP The guy who’s talkin’ Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Manuel Rauber
  2. Web APIs Node.js TypeScript Restify Database Deployment Examples Web-APIs mit

    Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Talking Points
  3. Overview Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA!

    2017 Web APIs Web API Node.js/.NETCore Browser GET /api/customer/1 Authorization: Bearer <token> File system PostgreSQL Elasticsearch validate token get token STS 1 2 3 4
  4. 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 HTTPS speaking client • Can involve WebSocket for real-time Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Web APIs HTTP HTTPS WebSocket Service A Service B Service C Web APIs (ASP.NET, Node.js, …) AuthN & AuthZ Client
  5. 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 • Work in progress: Microsoft’s ChakraCore as an alternative runtime Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Node.js
  6. Features • ECMAScript 6 • Experimental ECMAScript 7 • http://node.green/

    • Classes • Typed arrays • Fat Arrow/Lambda Expressions • Templated Strings Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Node.js
  7. Pros • Full stack JS’ish development • Universal JavaScript: Share

    code between client & server • Open Source loving community • Enterprise proven: Netflix, Paypal, Groupon, Walmart, … Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Node.js https://nodejs.org/static/documents/casestudies/Node_CaseStudy_Nasa_FNL.pdf
  8. Watch out! • Single threaded Event Loop: Avoid heavy CPU

    usage • Utilizes one CPU only: Scale via clustering • Relational databases can be strange – but it’s getting better! • Code is (often the only) documentation Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Node.js
  9. • Designed by Anders Hejlsberg, who also designed C# •

    Typed superset of JavaScript that transpiles to plain JavaScript • Types are optional, but useful metadata for tooling • Static Code Analysis • Refactoring • Linting • IntelliSense Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 TypeScript
  10. • Node.js module to build Web APIs • Middleware support

    • Client & server components • Routing • Useful plugins included • Used by Netflix, reddit, npm Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 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. Overview • Securing resources (APIs): Authentication & Authorization • OAuth

    2 Protocol: standard method for web, mobile and desktop applications • OpenID Connect: Identity Layer on top of OAuth 2 Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Token Authentication
  12. Node.js • Several node packages oidc-provider, assport, oauth2-server, oauth2orize, OpenIdConnect,

    node-oauth2-provider • State-of-the-art-package: oidc-provider • Implements a lot of OpenID Connect protocols • Certified by OpenID Connect • Customization needs to be done • Alternatives • IdentityServer 4 (.NET Core) • WSO2 (Java) Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Token Authentication
  13. • Adapters for a lot of databases • NoSQL databases

    MongoDB, CouchDB, … • Relational databases MSSQL, PostgreSQL, MySQL, SQLite, … • TypeORM as a type-safe ORM, but currently in alpha state Multiple databases, transactions, migrations, query API • Alternative: SequelizeJS, more mature Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Databases
  14. • Dockerize it! • Deployable via Docker containers on •

    Microsoft Azure: Container Registry, Container Services, Container Instances • IBM Bluemix Container Services • Amazon EC2 Container Services • Google Cloud Platform • Runnable via • Simple Azure Linux-based Web Apps • Docker Swarm • Kubernetes Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Deployment
  15. The unspoken things of the talk • API Rate Limiting/Throttling

    • Versioning • Caching • Gzipping • Content Negotiation • Cross-origin resource sharing (CORS) • Documentation • API Discovery • Real-time communication via WebSocket (e.g. Socket.io) • Security Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 That’s all?
  16. • Node.js overview Feature support, Node.js server, pros, watch outs

    • Web APIs with restify Routing, middlewares • Relational databases via TypeORM Models, query API • A lot more to discover Real-time communication, security, throttling, rate limitting Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Summary
  17. eBook & entwickler.de API special Web-APIs mit Node.js und TypeScript

    - für .NET-Entwickler BASTA! 2017 Read on! https://entwickler.de/press/shortcuts/die-serverwelt-von-node-js-2-262553.html https://entwickler.de/entwickler-magazin/entwickler-magazin-spezial-vol-13-apis-579812053.html
  18. • 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/ • TypeORM: https://typeorm.github.io/ • SequelizeJS: http://sequelizejs.com/ Web-APIs mit Node.js und TypeScript - für .NET-Entwickler BASTA! 2017 Resources
  19. Thank you! Questions? Repository Web-APIs mit Node.js und TypeScript -

    für .NET-Entwickler https://github.com/thinktecture/basta-herbst-2017-nodejs-typescript Contact @manuelrauber [email protected]