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

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

Web-APIs mit Node.js für .NET-Entwickler – über den Tellerrand geblickt

Full Stack JavaScript: Die Zeit, in der JavaScript nur am Client eingesetzt wurde, ist vorbei. Seit Node.js lassen sich auch serverseitige Applikationen mit JS – alternativ zu .NET – entwickeln. Lassen Sie uns gemeinsam einen Blick in die Welt von Node.js werfen und sehen, mit welchen Mitteln moderne Web-APIs entwickelt werden können. Nutzen wir die Vorteile von Node.js, wie Asynchronität und Performance, ohne dabei auf Absicherung per Token Authentication und Datenbankanbindung zu verzichten. Manuel Rauber liefert einen Überblick über verschiedene Aspekte von HTTP-basierten Services mit Node.js, sodass Sie auf dieser Grundlage Ihr „next generation“ Web-API entwickeln können. Und das mit erstaunlich wenig Zeilen Code.

GitHub: https://github.com/thinktecture/nodejs-aspnetcore-webapi/

Manuel Rauber

March 03, 2016
Tweet

More Decks by Manuel Rauber

Other Decks in Programming

Transcript

  1. WEB APIS - OVERVIEW REST APIs, HTTP APIs, whatever APIs

    Model functional services with dedicated interfaces Can use several other services for data aggregation Secured by tokens Consumable by every client which can speak HTTP(S)
  2. NODE.JS - INTRO Server-side JavaScript powered by Chrome's V8 JavaScript

    Engine Asynchronous, event-driven I/O API NuGet-like package manager: Node Package Manager (npm) Cross platform: OS X, Windows, Linux Upcoming: alternative runtime Microsoft's ChakraCore
  3. NODE.JS - FEATURE SUPPORT ECMAScript 6 Experimental ECMAScript 7 Classes

    Typed arrays Fat Arrow/Lambda Expressions Templated Strings
  4. NODE.JS - ASP.NET CORE 1.0 Node.js ASP.NET Core 1.0 JS,

    TS, CS, ... Node Package Manager Dynamic types Single threaded Event Loop but async I/O threads C# NuGet Static types Multi threaded
  5. NODE.JS - PROS Full stack JS development Universal JavaScript Same

    code on client and server Built-in streaming Open Source loving community Enterprise proven Paypal, Netflix, Groupon
  6. NODE.JS - WATCH OUT Single threaded Event Loop Avoid heavy

    CPU usage via JS Utilizes one CPU only Scale via clustering Relational databases can be strange Code is documentation
  7. RESTIFY - OVERVIEW Node.js module to build Web APIs Middleware

    support (OWIN like) Client and server components Routing
  8. RESTIFY - MIDDLEWARE c o n s t s e

    r v e r = r e s t i f y . c r e a t e S e r v e r ( ) ; / / R u n s b e f o r e . u s e h a n d l e r s s e r v e r . p r e ( ( r e q , r e s , n e x t ) = > { / * D o s o m e t h i n g * / } ) ; / / R u n s a f t e r . p r e h a n d l e r s s e r v e r . u s e ( ( r e q , r e s , n e x t ) = > { / * D o s o m e t h i n g * / } ) ; / / S a m p l e : U s i n g a p r e d e f i n e d m i d d l e w a r e s e r v e r . u s e ( r e s t i f y . b o d y P a r s e r ( ) ) ;
  9. ASP.NET CORE 1.0 - MIDDLEWARE p u b l i

    c v o i d C o n f i g u r e S e r v i c e s ( I S e r v i c e C o l l e c t i o n s e r v i c e s ) { / / A d d a p r e d e f i n e d m i d d l e w a r e s e r v i c e s . A d d M v c ( ) ; } p u b l i c v o i d C o n f i g u r e ( I A p p l i c a t i o n B u i l d e r a p p , I H o s t i n g E n v i r o n m e n t e n v , I L o g g e r F a c t o r y l o g g e r F a c t o r y ) { / / U s e a p r e d e f i n e d m i d d l e w a r e a p p . U s e M v c ( ) ; }
  10. RESTIFY - ROUTING / / H T T P G

    E T s e r v e r . g e t ( ' / h e l l o ' , ( r e q , r e s ) = > r e s . s e n d ( 2 0 0 , ' H e l l o W o r l d ' ) ) ; / / H T T P P O S T s e r v e r . p o s t ( ' / u p l o a d ' , s o m e M i d d l e w a r e ) ; / / H T T P P U T s e r v e r . p u t ( ' / c u s t o m e r / : i d ' , m i d d l e w a r e 1 , m i d d l e w a r e 2 ) ; / / H T T P D E L E T E s e r v e r . d e l ( ' / c u s t o m e r / : i d ' , a n o t h e r M i d d l e w a r e ) ;
  11. ASP.NET CORE 1.0 - ROUTING [ H t t p

    G e t ( " h e l l o " ) ] p u b l i c I A c t i o n R e s u l t G e t ( ) { r e t u r n O k ( " H e l l o W o r l d " ) ; } [ H t t p P o s t ( " u p l o a d " ) ] p u b l i c I A c t i o n R e s u l t P o s t ( ) { } [ H t t p P u t ( " c u s t o m e r / { i d } " ) ] p u b l i c I A c t i o n R e s u l t P u t ( i n t i d ) { } [ H t t p D e l e t e ( " c u s t o m e r / { i d } " ) ] p u b l i c I A c t i o n R e s u l t D e l e t e ( ) { }
  12. TOKEN AUTH - OVERVIEW Securing resources (APIs) OAuth2 Protocol Simple

    & standard method for web, mobile and desktop applications OpenId Connect Identity Layer on top of OAuth2
  13. TOKEN AUTH - NODE.JS Several node packages oauth2-server, oauth2orize, OpenIdConnect,

    node-oauth2-provider Currently no state-of-the-art package Implementation depends on the used package
  14. DATABASES - NODE.JS Adapters for lots of databases NoSQL databases

    MongoDB, CouchDB Relational databases MSSQL, PostgreSQL, MySQL, Sqlite ORM: SequelizeJS Multiple databases, transactions, migrations, replication, query API
  15. DATABASES - ASP.NET CORE 1.0 Entity Framework 7 Supports multiple

    databases MSSQL, Sqlite, InMemory, PostgreSQL Code First, Database First Migrations
  16. SUMMARY Node.js overview Feature support, Node.js server, pros, watch-out Web

    APIs with restify Routing, middlewares Token Authentication via OAuth2 OAuth2, outh2-server Relational databases via SequelizeJS Models, Query-API
  17. SECURE DATA ACCESS Mobile Apps und Zugriff auf Unternehmensdaten ohne

    Cloud-Speicher und VPN Manuel Rauber Christian Weyer Today at 14:00 in room Würzburg
  18. RESOURCES GitHub repository: Node.js: Node.js at Paypal: Node.js at Netflix:

    Node.js at Walmart: Restify: SequelizeJS: ASP.NET Core 1.0: Entity Framework 7: IdentityServer4: Angular 2: Channel9: https://github.com/thinktecture/nodejs-aspnetcore-webapi https://nodejs.org/ https://www.paypal-engineering.com/?s=node http://techblog.netflix.com/search/label/node.js https://www.joyent.com/developers/videos/node-js-at-walmart-introduction http://restify.com/ http://sequelizejs.com/ https://docs.asp.net/ http://docs.efproject.net/ https://github.com/IdentityServer/IdentityServer4 https://angular.io/ https://channel9.msdn.com/Series/Thementag-Cross-Plattform-Entwicklung-mit- HTML5--Javascript