$30 off During Our Annual Pro Sale. View Details »

Web APIs with Node.js for .NET developers

Web APIs with Node.js for .NET developers

JavaScript - for a lot of developers it's the typical jQuery syntax "$(...)" creating spaghetti code. And then use JavaScript for some serious backend development? Node.js changed that a lot. The client-only view of JavaScript has ended. Node.js can be used to develop modern and lightweight web APIs using runtime advantages like asynchronous I/O and performance, without having to quit token authentication or database access.

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

Manuel Rauber

February 18, 2016

More Decks by Manuel Rauber

Other Decks in Programming



    Rauber thinktecture.com
  2. INTRODUCTION Manuel Rauber manuel.rauber@thinktecture.com @manuelrauber https://manuel-rauber.com

  3. TALKING POINTS Web APIs Node.js Restify Token Authentication Databases Examples




    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)
  7. NODE.JS


  9. 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
  10. NODE.JS - FEATURE SUPPORT ECMAScript 6 Experimental ECMAScript 7 Classes

    Typed arrays Fat Arrow/Lambda Expressions Templated Strings
  11. 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

  13. 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
  14. 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

  16. RESTIFY - OVERVIEW Node.js module to build Web APIs Middleware

    support (OWIN like) Client and server components Routing
  17. 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 ( ) ) ;
  18. 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 ( ) ; }

    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 ) ;
  20. 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 ( ) { }

  22. 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
  23. 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
  24. TOKEN AUTH - ASP.NET CORE 1.0 State-of-the-art package IdentityServer4


  26. 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
  27. DATABASES - ASP.NET CORE 1.0 Entity Framework 7 Supports multiple

    databases MSSQL, Sqlite, InMemory, PostgreSQL Code First, Database First Migrations

  29. THANK YOU! GitHub repository https://github.com/thinktecture/nodejs-aspnetcore-webapi thinktecture.com

  30. 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: 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/