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

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

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. INTRODUCTION
    Manuel Rauber
    [email protected]
    @manuelrauber
    https://manuel-rauber.com

    View full-size slide

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

    View full-size slide

  3. WEB APIS - OVERVIEW

    View full-size slide

  4. 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)

    View full-size slide

  5. NODE.JS IS
    NOT
    JQUERY IN COOL ;-)

    View full-size slide

  6. 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

    View full-size slide

  7. NODE.JS - FEATURE SUPPORT
    ECMAScript 6
    Experimental ECMAScript 7
    Classes
    Typed arrays
    Fat Arrow/Lambda
    Expressions
    Templated Strings

    View full-size slide

  8. 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

    View full-size slide

  9. NODE.JS - SERVER

    View full-size slide

  10. 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

    View full-size slide

  11. 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

    View full-size slide

  12. RESTIFY - OVERVIEW
    Node.js module to build Web
    APIs
    Middleware support (OWIN like)
    Client and server components
    Routing

    View full-size slide

  13. 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
    (
    )
    )
    ;

    View full-size slide

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

    View full-size slide

  15. 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
    )
    ;

    View full-size slide

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

    View full-size slide

  17. TOKEN
    AUTHENTICATION

    View full-size slide

  18. 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

    View full-size slide

  19. 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

    View full-size slide

  20. TOKEN AUTH - ASP.NET CORE 1.0
    State-of-the-art
    package
    IdentityServer4

    View full-size slide

  21. 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

    View full-size slide

  22. DATABASES - ASP.NET CORE 1.0
    Entity Framework 7
    Supports multiple databases
    MSSQL, Sqlite, InMemory, PostgreSQL
    Code First, Database First
    Migrations

    View full-size slide

  23. 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

    View full-size slide

  24. 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

    View full-size slide

  25. CHANNEL9
    Cross-Platform Development
    https://channel9.msdn.com/Series/Thementag-Cross-
    Plattform-Entwicklung-mit-HTML5--Javascript

    View full-size slide

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

    View full-size slide

  27. 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

    View full-size slide