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

Pragmatische Web APIs mit Node.js

Pragmatische Web APIs mit Node.js

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 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 Ihre „Next Generation“ Web API entwickeln können. Und das mit erstaunlich wenig Zeilen Code.

GitHub Repository: https://github.com/thinktecture/apisummit-2016-node-webapi

Manuel Rauber

November 23, 2016
Tweet

More Decks by Manuel Rauber

Other Decks in Programming

Transcript

  1. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Manuel Rauber
    @manuelrauber | [email protected]
    Software Architect

    View Slide

  2. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Manuel Rauber
    Software Architect @ Thinktecture AG
    ! [email protected]
    " @manuelrauber
    # https://manuel-rauber.com
    Microsoft MVP
    That’s me!
    The guy who’s talkin’

    View Slide

  3. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Web APIs
    Node.js
    Restify
    Token Authentication
    Database
    Examples
    Talking Points

    View Slide

  4. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Overview
    Web APIs

    View Slide

  5. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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
    Web APIs

    View Slide

  6. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Node.js is
    not
    jQuery in cool ;-)
    Node.js

    View Slide

  7. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  8. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Features
    • ECMAScript 6
    • Experimental ECMAScript 7
    • http://node.green/
    • Classes
    • Typed arrays
    • Fat Arrow/Lambda Expression
    • Templated Strings
    Node.js

    View Slide

  9. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  10. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Server Architecture
    Node.js

    View Slide

  11. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  12. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  13. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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 …

    View Slide

  14. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  15. Pragmatische Web APIs mit Node.js
    API Summit 2016
    Node.js
    • Several node packages
    oauth2-server, oauth2orize, OpenIdConnect, node-oauth2-provider
    • Currently no state-of-the-art package: Leverage third-party applications like IdentityServer
    • Implementation depends on the used package
    Token Authentication

    View Slide

  16. Pragmatische Web APIs mit Node.js
    API Summit 2016
    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

    View Slide

  17. Pragmatische Web APIs mit Node.js
    API Summit 2016
    DEMO

    View Slide

  18. Pragmatische Web APIs mit Node.js
    API Summit 2016
    • 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

    View Slide

  19. Pragmatische Web APIs mit Node.js
    API Summit 2016
    eBook
    Die Serverwelt von Node.js
    https://entwickler.de/press/shortcuts/die-serverwelt-von-node-js-2-262553.html

    View Slide

  20. Pragmatische Web APIs mit Node.js
    API Summit 2016
    • 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

    View Slide

  21. Thank you! Questions?
    Repository
    https://github.com/thinktecture/apisummit-2016-node-webapi
    Contact
    @manuelrauber
    [email protected]

    View Slide