Slide 1

Slide 1 text

Web-APIs mit Node.js und TypeScript Leichtgewichtig & Performant Manuel Rauber @manuelrauber Consultant

Slide 2

Slide 2 text

Consultant @ Thinktecture AG ! manuel.rauber@thinktecture.com " @manuelrauber # https://manuel-rauber.com Microsoft MVP The guy who’s talkin’ Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 Manuel Rauber

Slide 3

Slide 3 text

Web APIs Node.js TypeScript Restify Database Deployment Examples Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 Talking Points

Slide 4

Slide 4 text

Overview Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 Web APIs Web API Node.js/.NETCore Browser GET /api/customer/1 Authorization: Bearer File system PostgreSQL Elasticsearch validate token get token STS 1 2 3 4

Slide 5

Slide 5 text

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 - leichtgewichtig und performant API Conference 2017 Web APIs HTTP HTTPS WebSocket Service A Service B Service C Web APIs (ASP.NET, Node.js, …) AuthN & AuthZ Client

Slide 6

Slide 6 text

Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 Node.js is not jQuery in cool ;-) Node.js

Slide 7

Slide 7 text

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 - leichtgewichtig und performant API Conference 2017 Node.js

Slide 8

Slide 8 text

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 - leichtgewichtig und performant API Conference 2017 Node.js

Slide 9

Slide 9 text

Server Architecture Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 Node.js

Slide 10

Slide 10 text

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 - leichtgewichtig und performant API Conference 2017 Node.js https://nodejs.org/static/documents/casestudies/Node_CaseStudy_Nasa_FNL.pdf

Slide 11

Slide 11 text

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 - leichtgewichtig und performant API Conference 2017 Node.js

Slide 12

Slide 12 text

• Designed by Anders Heijsberg, 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 - leichtgewichtig und performant API Conference 2017 TypeScript

Slide 13

Slide 13 text

• 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 - leichtgewichtig und performant API Conference 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 …

Slide 14

Slide 14 text

• 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 - leichtgewichtig und performant API Conference 2017 Databases

Slide 15

Slide 15 text

• 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 - leichtgewichtig und performant API Conference 2017 Deployment

Slide 16

Slide 16 text

Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 2017 DEMO

Slide 17

Slide 17 text

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 - leichtgewichtig und performant API Conference 2017 That’s all?

Slide 18

Slide 18 text

• 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 - leichtgewichtig und performant API Conference 2017 Summary

Slide 19

Slide 19 text

eBook & entwickler.de API special Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant API Conference 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

Slide 20

Slide 20 text

• 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 - leichtgewichtig und performant API Conference 2017 Resources

Slide 21

Slide 21 text

Thank you! Questions? Repository Web-APIs mit Node.js und TypeScript - leichtgewichtig und performant https://github.com/thinktecture/api-conference-2017-nodejs-typescript-webapi Contact @manuelrauber manuel.rauber@thinktecture.com