Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Modern Web APIs with Node.js & TypeScript

Modern Web APIs with Node.js & TypeScript

Full-Stack-Development! Modern frontends are using Single-Page Applications like Angular or React communicating with some light-weight Web APIs in the background. Thanks to Node.js we can speak one language in both worlds: JavaScript … or even TypeScript! Within this session we want to take a look at building (lots of live coding!) modern and light-weight Web APIs based on Node.js with TypeScript and connect to a database using an ORM called TypeORM. A few lines of code are needed to create a “next generation” Web API.

GitHub: https://github.com/thinktecture/javascript-conference-2017-nodejs-typescript

Manuel Rauber

October 24, 2017
Tweet

More Decks by Manuel Rauber

Other Decks in Programming

Transcript

  1. Consultant @ Thinktecture AG ! [email protected] " @manuelrauber # https://manuel-rauber

    .com Microsoft MVP The guy who’s talkin’ Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Manuel Rauber
  2. Web APIs Node.js TypeScript Restify Database Deployment Examples Modern Web

    APIs with Node.js & TypeScript International JavaScript Conference 2017 Talking Points
  3. Overview Modern Web APIs with Node.js & TypeScript International JavaScript

    Conference 2017 Web APIs Web API Node.js/.NETCore Browser GET /api/customer/1 Authorization: Bearer <token> File system PostgreSQL Elasticsearch validate token get token STS 1 2 3 4
  4. 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Web APIs HTTP HTTPS WebSocket Service A Service B Service C Web APIs (ASP.NET, Node.js, …) AuthN & AuthZ Client
  5. Node.js Node.js is not jQuery in cool ;-) Modern Web

    APIs with Node.js & TypeScript International JavaScript Conference 2017
  6. 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Node.js
  7. Features • ECMAScript 6 • Experimental ECMAScript 7 • http://node.green/

    • Classes • Typed arrays • Fat Arrow/Lambda Expressions • Templated Strings Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Node.js
  8. Pros • Full stack JS’ish development • Universal JavaScript: Share

    code between client & server • Open Source loving community • Enterprise proven: Netflix, Paypal, Groupon, Walmart, … Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Node.js https://nodejs.org/static/documents/casestudies/Node_CaseStudy_Nasa_FNL.pdf
  9. 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Node.js
  10. • Designed by Anders Hejlsberg, 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 TypeScript
  11. • Node.js module to build Web APIs • Middleware support

    • Client & server components • Routing • Useful plugins included • Used by Netflix, reddit, npm Modern Web APIs with Node.js & TypeScript International JavaScript 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 …
  12. • 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Databases
  13. • 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Deployment
  14. 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 Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 That’s all?
  15. • 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 limiting Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Summary
  16. eBook & entwickler .de API special Modern Web APIs with

    Node.js & TypeScript International JavaScript 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
  17. • 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/ Modern Web APIs with Node.js & TypeScript International JavaScript Conference 2017 Resources
  18. Thank you! Questions? Repository Modern Web APIs with Node.js &

    TypeScript https://github.com/thinktecture/javascript-conference-2017-nodejs-typescript Contact @manuelrauber [email protected]