SlideShare a Scribd company logo
1 of 45
Download to read offline
@djidja8
This deck and code are on GitHub:
https://github.com/srdjan/resto
Node.js is a cross-platform runtime environment and a set of libraries for server side applications written in JavaScript
== Runtime + Libraries + REPL + Package Manager
๏‚ง V8 JavaScript runtime:
V8 is Google's open source JavaScript engine written in
C++ and used in Google's open source browser Chrome
๏‚ง libuv:
A cross-platform library that abstracts OS host platform
system and: provides an event loop with callback based
notifications for Async I/O and other activities, timers,
non-blocking networking support, asynchronous file
system access, child processes and more.
๏‚ง Non-blocking standard libraries:
Async + streams = highly concurrent, and it works well
for IO-bound workloads (but it is not parallelism).
REPL (readโ€“evalโ€“print loop)
provides a way to interactively run JavaScript and
see the results. It can be used for debugging, testing,
or just trying things out. It is available both as a
standalone program and easily embeddable in other
programs.
NPM is the official package manager for Node.js and is written entirely in JavaScript. It is bundled and installed
automatically with the environment. It has the command line interface and manages packages (modules)
dependencies for an application.
NPM enables you to install, publish, manage, and distribute JavaScript code easily
NPM install and uninstall commands
Other useful commands
Not only for NodeJs, Browserify enables using NPM modules when developing for browser too!
Allows a node-style code organization when developing for browser and use of modules installed by NPM
Node.js provides the file system module, fs. For the most part, fs simply provides a wrapper for the standard file
operations. The following example uses the fs module to read contents of a file into memory
The HTTP interfaces in Node are designed to support many features of the protocol which have been traditionally
difficult to use. In particular, large, possibly chunk-encoded, messages. http module never buffers entire requests
or responses
๏‚ง Single threaded / Async
I/O is provided by simple wrappers around standard POSIX functions. All the methods have asynchronous
and synchronous forms, but Async is default.
๏‚ง Most APIs speak Streams:
The built-in stream module is used by the core libraries and can also be used by user-space modules, while
providing a backpressure mechanism to throttle writes for slow consumers
๏‚ง Extensible via C/C++ add-ons:
Node.js is extensible and modules can include add-ons written in native code
๏‚ง Local scope:
Browser JavaScript lifts everything into its global scope, Node.js was designed to have everything being local by
default. Exporting is done explicitly, and in case we need to access globals, there is a global object.
๏‚ง Development efficiency
Web development in a dynamic language (JavaScript) and great package manager (NPM)
๏‚ง Performant
Ability to handle thousands of concurrent connections with minimal overhead on a single process.
๏‚ง Familiar
People already know how to use JavaScript, having used it in the browser.
๏‚ง Full stack development
Using JavaScript on a web server as well as the browser reduces the impedance mismatch
between the two programming environments (+ JSON)
๏‚ง What is Express.js?
๏‚ง Hello World
๏‚ง Request and Response
๏‚ง Router
๏‚ง Middleware
A minimal and flexible node.js web application framework, providing a robust set of features for building full web
applications and/or APIs.
โ€ข Middleware
โ€ข Routing
โ€ข Templating engines
โ€ข Layouts and partial views
โ€ข Environment-based configuration
http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/
A router object is an isolated instance of middleware and routes, capable only of performing middleware and
routing functions.
A router behaves like middleware itself, so you can use it as an argument to app.use() or as the argument to
another routerโ€™s use() method.
Every Express application has a built-in app router:
Chainable route handlers for a route path can be created using app.route().
Since the path is specified at a single location, it helps to create modular routes and reduce redundancy and typos.
The express.Router class can be used to create modular mountable route handlers. A Router instance is a complete
middleware and routing system; for this reason it is often referred to as a โ€œmini-appโ€
And then
Middleware is the core concept behind Express.js request processing and routing and is composed from any
number of functions that are invoked by the Express.js routing layer before final application request handler is
invoked.
๏‚ง Application-level middleware
๏‚ง Router-level middleware
๏‚ง Error-handling middleware
๏‚ง Built-in middleware
๏‚ง Third-party middleware
Middleware function signature is simple:
Express.js has great built in capabilities to serve static content. The module is able to also gzip compress and/or
cache served files, tooโ€ฆ
*As of 4.x, all of Express' previously included middleware are now in separate repositories. The only included
middleware is: express.static(), used to server static files.
Error-handling middleware are defined just like regular middleware, however must be defined with an arity of 4
signature: (error, request, response, next)
error-handling middleware are typically defined very last, below any other app.use() calls...
All of Express' previously (before v4.0) included middleware are now in separate repos. Here are some example
middleware modules:
๏‚ง body-parser
๏‚ง compression
๏‚ง connect-timeout
๏‚ง csurf
๏‚ง errorhandler
๏‚ง method-override
๏‚ง morgan - previously logger
๏‚ง response-time
๏‚ง serve-favicon
๏‚ง Koa
Koa is designed by the team behind Express, which aims to be a smaller, more
expressive, and more robust foundation for web applications and APIs.
Through leveraging generators Koa allows you to ditch callbacks and greatly
increase error-handling
๏‚ง Restify
restify is a node.js module built specifically to enable you to build correct REST
web services. It intentionally borrows heavily from express as that is more or
less the de facto API for writing web applications on top of node.js.
๏‚ง Hapi
hapi is a simple to use configuration-centric framework with built-in support
for input validation, caching, authentication, and other essential facilities for
building web and services applications.
๏‚ง Hypermedia driven?
๏‚ง Media types?
๏‚ง Uniform interface?
๏‚ง Stateless?
๏‚ง Hypermedia driven?
๏‚ง Media types?
http://events.layer7tech.com/state-api
๏‚ง Stateless?
๏‚ง Uniform interface?
roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
Generic:
text/html
application/xml
application/json
Generic with hypermedia elements:
application/hal+json
application/json-ld
Domain Specific:
application/vnd.mymediatype-v2+json
Media Types define:
1. How is byte stream encoded and how to locate hypermedia elements
2. What the data represents
Format: typeโ€/โ€subtype *(โ€œ;โ€ parameter)
Used in: โ€œAcceptโ€ and โ€œContentTypeโ€ headers
Avoid generic media types (like JSON and XML) - they do not include hypermedia elements
Choice:
1) Use few (one?) generic media types with hypermedia elements
( to avoid the need for clients to understand too many )
+ the domain specific media types identified by a profile โ€“
in the payload or in a HTTP header
or
2) Use many different domain specific media types?
HAL is designed for building APIs in which clients navigate around the resources by following links. Links are
identified by link relations, the lifeblood of a hypermedia API: they are how you tell client developers about what
resources are available and how they can be interacted with, and they are how the code they write will select
which link to traverse
HAL - Specification
The architectural properties affected by the constraints of the REST architectural style are:[4][6]
- Performance - component interactions can be the dominant factor in user-perceived performance and network efficiency.[7]
- Scalability to support large numbers of components and interactions among components. Roy Fielding, one of the principal
authors of the HTTP specification, describes REST's effect on scalability thus:
REST's clientโ€“server separation of concerns simplifies component implementation, reduces the complexity of connector
semantics, improves the effectiveness of performance tuning, and increases the scalability of pure server components. Layered
system constraints allow intermediariesโ€”proxies, gateways, and firewallsโ€”to be introduced at various points in the
communication without changing the interfaces between components, thus allowing them to assist in communication
translation or improve performance via large-scale, shared caching. REST enables intermediate processing by constraining
messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to
indicate semantics and exchange information, and responses explicitly indicate cacheability.[4]
Simplicity of interfaces
Modifiability of components to meet changing needs (even while the application is running)
Visibility of communication between components by service agents
Portability of components by moving program code with the data
Reliability is the resistance to failure at the system level in the presence of failures within components, connectors, or data[7]
๏‚ง Uniform Interface
๏‚ง Stateless
๏‚ง Cacheable
๏‚ง Client-Server
๏‚ง Layered System
๏‚ง Code on Demand (optional)
The uniform interface constraint defines the interface between clients and servers. It simplifies and decouples
the architecture and enables each part to evolve independently. The four guiding principles of the uniform
interface are:
๏‚ง Resource-Based
Individual resources are identified in requests using URIs as resource identifiers. The resources themselves are
conceptually separate from the representations that are returned to the client
๏‚ง Manipulation of Resources Through Representations
When a client holds a representation of a resource, including any metadata attached, it has enough information
to modify or delete the resource on the server, provided it has permission to do so
๏‚ง Self-descriptive Messages
Each message includes enough information to describe how to process the message. For example, which parser
to invoke may be specified by an Internet media type (previously known as a MIME type)
๏‚ง Hypermedia as the Engine of Application State (HATEOAS)
HATEOS is the key constrain that makes web browsing possible. Applicable to APIs but not widely used. It is
simple to understand: each response message includes the links to next possible request message.
As REST is an acronym for REpresentational State Transfer, server statelessness is key.
Essentially, what this means is that the necessary state to handle the request is contained within the request
itself, whether as part of the URI, query-string parameters, body, or headers
Clients handle application state, servers resource state
Application state is information about where you are in the interaction that is used during your session with an
application.
Resource state is the kind of (semi-)permanent data a server stores, and lasts beyond the duration of a single session of
interactions.
The goal of caching is never having to generate the same response twice. The benefit of doing this is that we gain
speed and reduce server load.
๏‚ง Expiration
๏‚ง Expires header
๏‚ง Cache-Control header
๏‚ง Validation
๏‚ง Last-Modified header
๏‚ง ETag header
The client-server constraint is based on a principle known as the separation of concerns. It simply requires the
existence of a client component that sends requests and a server component that receives requests
Servers and clients may also be replaced and developed independently, as long as the interface is not altered
REST architecture is conceived as hierarchical layers of components, limited to communication with their
immediate neighbors.
A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the
way.
The optional code-on-demand constraint allows clients to request and execute code from servers. This, in turn,
allows the server to deploy new features to clients. The result is improved extensibility and configurability for
servers, and improved performance and efficiency for clients
Level 0: Swamp of POX
tunnels requests and responses through its transport protocol,
using only one entry point (URI) and one kind of method (in HTTP,
this normally is the POST method). Examples of these are SOAP
and XML-RPC/JSON/RPC.
Level 1: Resources
This level uses multiple URIs, where every URI is the entry point to
a specific resource. Still, this level uses only one single method like
POST.
Level 2: (HTTP) verbs
This level suggests that in order to be truly RESTful, your API MUST
use limited set of verbs.
Level 3: Hypermedia controls
Level 3, the highest level, uses HATEOAS to deal with discovering
the possibilities of your API towards the clients.
๏‚ง Granular (leads to CRUD)
๏‚ง Not scalable
๏‚ง Low level
๏‚ง Chatty
๏‚ง Business logic moves to consumer
๏‚ง Coarse grained
๏‚ง Focus on business entities vs activities
๏‚ง Decoupled from internal domain implementation
๏‚ง Business logic contained on th eserver side
*Use only GET and POST (CQRS)?
github.com/Srdjan/restoCode repository:
This presentation on GitHub: Building Killer RESTful APIs
Node.Js
๏‚ง Mixu Online book
๏‚ง Why Asynchronous?
๏‚ง Mastering Node
Express
๏‚ง Express Home Page
๏‚ง Understanding Express.js
๏‚ง A short guide to Connect Middleware
REST APIs
๏‚ง REST API Tutorial
๏‚ง Restful Exploration
๏‚ง HAL - Hypertext Application Language
@djidja8

More Related Content

What's hot

แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จ
แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จแ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จ
แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จuEngine Solutions
ย 
Crx 2.2 Deep-Dive
Crx 2.2 Deep-DiveCrx 2.2 Deep-Dive
Crx 2.2 Deep-DiveGabriel Walt
ย 
Web Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureWeb Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureToru Kawamura
ย 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawnozten
ย 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 RefresherIvano Malavolta
ย 
Apache Etch Introduction @ FOSDEM 2011
Apache Etch Introduction @ FOSDEM 2011Apache Etch Introduction @ FOSDEM 2011
Apache Etch Introduction @ FOSDEM 2011grandyho
ย 
How do we drive tech changes
How do we drive tech changesHow do we drive tech changes
How do we drive tech changesJaewoo Ahn
ย 
Spring Mvc
Spring MvcSpring Mvc
Spring Mvcifnu bima
ย 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsVirtual Nuggets
ย 
Scripted - Embracing Eclipse Orion
Scripted - Embracing Eclipse OrionScripted - Embracing Eclipse Orion
Scripted - Embracing Eclipse Orionmartinlippert
ย 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Coremohamed elshafey
ย 
JavaOne 2015: 12 Factor App
JavaOne 2015: 12 Factor AppJavaOne 2015: 12 Factor App
JavaOne 2015: 12 Factor AppJoe Kutner
ย 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7Shekhar Gulati
ย 
Data Persistence as a Language Feature
Data Persistence as a Language FeatureData Persistence as a Language Feature
Data Persistence as a Language FeatureRob Tweed
ย 
AngularJS Anatomy & Directives
AngularJS Anatomy & DirectivesAngularJS Anatomy & Directives
AngularJS Anatomy & DirectivesDigikrit
ย 
Simple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerSimple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerLeanIX GmbH
ย 

What's hot (20)

แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จ
แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จแ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จ
แ„‰แ…ฅแ†ผแ„€แ…ฉแ†ผแ„Œแ…ฅแ†จแ„‹แ…ตแ†ซ แ„‰แ…ฅแ„‡แ…ตแ„‰แ…ณแ„…แ…ฉแ„‹แ…ด แ„‘แ…ณแ†ฏแ„…แ…ขแ†บแ„‘แ…ฉแ†ท แ„‰แ…ฅแ†ซแ„แ…ขแ†จ
ย 
Crx 2.2 Deep-Dive
Crx 2.2 Deep-DiveCrx 2.2 Deep-Dive
Crx 2.2 Deep-Dive
ย 
Metaworks4 intro
Metaworks4 introMetaworks4 intro
Metaworks4 intro
ย 
Web Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureWeb Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the future
ย 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
ย 
HTML5 Refresher
HTML5 RefresherHTML5 Refresher
HTML5 Refresher
ย 
Apache Etch Introduction @ FOSDEM 2011
Apache Etch Introduction @ FOSDEM 2011Apache Etch Introduction @ FOSDEM 2011
Apache Etch Introduction @ FOSDEM 2011
ย 
How do we drive tech changes
How do we drive tech changesHow do we drive tech changes
How do we drive tech changes
ย 
Spring Mvc
Spring MvcSpring Mvc
Spring Mvc
ย 
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap โ€“ Duลกko Vukmanoviฤ‡
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap โ€“ Duลกko Vukmanoviฤ‡JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap โ€“ Duลกko Vukmanoviฤ‡
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap โ€“ Duลกko Vukmanoviฤ‡
ย 
Spring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggetsSpring Framework Tutorial | VirtualNuggets
Spring Framework Tutorial | VirtualNuggets
ย 
Scripted - Embracing Eclipse Orion
Scripted - Embracing Eclipse OrionScripted - Embracing Eclipse Orion
Scripted - Embracing Eclipse Orion
ย 
Ecom 1
Ecom 1Ecom 1
Ecom 1
ย 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
ย 
JavaOne 2015: 12 Factor App
JavaOne 2015: 12 Factor AppJavaOne 2015: 12 Factor App
JavaOne 2015: 12 Factor App
ย 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
ย 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7
ย 
Data Persistence as a Language Feature
Data Persistence as a Language FeatureData Persistence as a Language Feature
Data Persistence as a Language Feature
ย 
AngularJS Anatomy & Directives
AngularJS Anatomy & DirectivesAngularJS Anatomy & Directives
AngularJS Anatomy & Directives
ย 
Simple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and SwaggerSimple REST-APIs with Dropwizard and Swagger
Simple REST-APIs with Dropwizard and Swagger
ย 

Similar to Building Killer RESTful APIs with NodeJs

Vijay Oscon
Vijay OsconVijay Oscon
Vijay Osconvijayrvr
ย 
All the amazing features of asp.net core
All the amazing features of asp.net coreAll the amazing features of asp.net core
All the amazing features of asp.net coreGrayCell Technologies
ย 
SERVER SIDE SCRIPTING
SERVER SIDE SCRIPTINGSERVER SIDE SCRIPTING
SERVER SIDE SCRIPTINGProf Ansari
ย 
Full Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeFull Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeIRJET Journal
ย 
NodeJs Frameworks.pdf
NodeJs Frameworks.pdfNodeJs Frameworks.pdf
NodeJs Frameworks.pdfWPWeb Infotech
ย 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Atharva Jawalkar
ย 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdfDarshanaMallick
ย 
TOLL MANAGEMENT SYSTEM
TOLL MANAGEMENT SYSTEMTOLL MANAGEMENT SYSTEM
TOLL MANAGEMENT SYSTEMvishnuRajan20
ย 
Toll management system (1) (1)
Toll management system (1) (1)Toll management system (1) (1)
Toll management system (1) (1)vishnuRajan20
ย 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
ย 
Ease of full Stack Development
Ease of full Stack DevelopmentEase of full Stack Development
Ease of full Stack DevelopmentIRJET Journal
ย 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
ย 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.suranisaunak
ย 
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx75waytechnologies
ย 
What is ASP.NET and Why do we need it?
What is ASP.NET and Why do we need it?What is ASP.NET and Why do we need it?
What is ASP.NET and Why do we need it?Natural Group
ย 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET Journal
ย 
Software Architecture for Robotics
Software Architecture for RoboticsSoftware Architecture for Robotics
Software Architecture for RoboticsLorran Pegoretti
ย 
Online furniture management system
Online furniture management systemOnline furniture management system
Online furniture management systemYesu Raj
ย 

Similar to Building Killer RESTful APIs with NodeJs (20)

Vijay Oscon
Vijay OsconVijay Oscon
Vijay Oscon
ย 
All the amazing features of asp.net core
All the amazing features of asp.net coreAll the amazing features of asp.net core
All the amazing features of asp.net core
ย 
SERVER SIDE SCRIPTING
SERVER SIDE SCRIPTINGSERVER SIDE SCRIPTING
SERVER SIDE SCRIPTING
ย 
Full Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeFull Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future Scope
ย 
NodeJs Frameworks.pdf
NodeJs Frameworks.pdfNodeJs Frameworks.pdf
NodeJs Frameworks.pdf
ย 
Best node js course
Best node js courseBest node js course
Best node js course
ย 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
ย 
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous  Blocking or synchronous.pdfNode Js Non-blocking or asynchronous  Blocking or synchronous.pdf
Node Js Non-blocking or asynchronous Blocking or synchronous.pdf
ย 
TOLL MANAGEMENT SYSTEM
TOLL MANAGEMENT SYSTEMTOLL MANAGEMENT SYSTEM
TOLL MANAGEMENT SYSTEM
ย 
Toll management system (1) (1)
Toll management system (1) (1)Toll management system (1) (1)
Toll management system (1) (1)
ย 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
ย 
Ease of full Stack Development
Ease of full Stack DevelopmentEase of full Stack Development
Ease of full Stack Development
ย 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
ย 
Analysis
AnalysisAnalysis
Analysis
ย 
Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.Introduction Java Web Framework and Web Server.
Introduction Java Web Framework and Web Server.
ย 
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
8 Node.js Frameworks Every Developer Should Know [UPDATED].pptx
ย 
What is ASP.NET and Why do we need it?
What is ASP.NET and Why do we need it?What is ASP.NET and Why do we need it?
What is ASP.NET and Why do we need it?
ย 
IRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce SiteIRJET- Rest API for E-Commerce Site
IRJET- Rest API for E-Commerce Site
ย 
Software Architecture for Robotics
Software Architecture for RoboticsSoftware Architecture for Robotics
Software Architecture for Robotics
ย 
Online furniture management system
Online furniture management systemOnline furniture management system
Online furniture management system
ย 

Recently uploaded

Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
ย 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...SUHANI PANDEY
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...SUHANI PANDEY
ย 
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort ServiceBusty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort ServiceDelhi Call girls
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...SUHANI PANDEY
ย 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
ย 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
ย 
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
ย 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...SUHANI PANDEY
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubaikojalkojal131
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
ย 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
ย 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
ย 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
ย 
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...nilamkumrai
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
ย 

Recently uploaded (20)

Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
ย 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
ย 
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐ŸฅตLow Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
ย 
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort ServiceBusty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
ย 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
ย 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
ย 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
ย 
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
๐Ÿ“ฑDehradun Call Girls Service ๐Ÿ“ฑโ˜Ž๏ธ +91'905,3900,678 โ˜Ž๏ธ๐Ÿ“ฑ Call Girls In Dehradun ๐Ÿ“ฑ
ย 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
ย 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
ย 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
ย 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
ย 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
ย 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
ย 
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls ๐ŸŽ—๏ธ 9352988975 Sizzling | Escorts | G...
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย 

Building Killer RESTful APIs with NodeJs

  • 2. This deck and code are on GitHub: https://github.com/srdjan/resto
  • 3. Node.js is a cross-platform runtime environment and a set of libraries for server side applications written in JavaScript == Runtime + Libraries + REPL + Package Manager
  • 4. ๏‚ง V8 JavaScript runtime: V8 is Google's open source JavaScript engine written in C++ and used in Google's open source browser Chrome ๏‚ง libuv: A cross-platform library that abstracts OS host platform system and: provides an event loop with callback based notifications for Async I/O and other activities, timers, non-blocking networking support, asynchronous file system access, child processes and more. ๏‚ง Non-blocking standard libraries: Async + streams = highly concurrent, and it works well for IO-bound workloads (but it is not parallelism).
  • 5. REPL (readโ€“evalโ€“print loop) provides a way to interactively run JavaScript and see the results. It can be used for debugging, testing, or just trying things out. It is available both as a standalone program and easily embeddable in other programs.
  • 6. NPM is the official package manager for Node.js and is written entirely in JavaScript. It is bundled and installed automatically with the environment. It has the command line interface and manages packages (modules) dependencies for an application. NPM enables you to install, publish, manage, and distribute JavaScript code easily
  • 7. NPM install and uninstall commands
  • 9. Not only for NodeJs, Browserify enables using NPM modules when developing for browser too! Allows a node-style code organization when developing for browser and use of modules installed by NPM
  • 10. Node.js provides the file system module, fs. For the most part, fs simply provides a wrapper for the standard file operations. The following example uses the fs module to read contents of a file into memory
  • 11. The HTTP interfaces in Node are designed to support many features of the protocol which have been traditionally difficult to use. In particular, large, possibly chunk-encoded, messages. http module never buffers entire requests or responses
  • 12. ๏‚ง Single threaded / Async I/O is provided by simple wrappers around standard POSIX functions. All the methods have asynchronous and synchronous forms, but Async is default. ๏‚ง Most APIs speak Streams: The built-in stream module is used by the core libraries and can also be used by user-space modules, while providing a backpressure mechanism to throttle writes for slow consumers ๏‚ง Extensible via C/C++ add-ons: Node.js is extensible and modules can include add-ons written in native code ๏‚ง Local scope: Browser JavaScript lifts everything into its global scope, Node.js was designed to have everything being local by default. Exporting is done explicitly, and in case we need to access globals, there is a global object.
  • 13. ๏‚ง Development efficiency Web development in a dynamic language (JavaScript) and great package manager (NPM) ๏‚ง Performant Ability to handle thousands of concurrent connections with minimal overhead on a single process. ๏‚ง Familiar People already know how to use JavaScript, having used it in the browser. ๏‚ง Full stack development Using JavaScript on a web server as well as the browser reduces the impedance mismatch between the two programming environments (+ JSON)
  • 14. ๏‚ง What is Express.js? ๏‚ง Hello World ๏‚ง Request and Response ๏‚ง Router ๏‚ง Middleware
  • 15. A minimal and flexible node.js web application framework, providing a robust set of features for building full web applications and/or APIs. โ€ข Middleware โ€ข Routing โ€ข Templating engines โ€ข Layouts and partial views โ€ข Environment-based configuration
  • 17.
  • 18. A router object is an isolated instance of middleware and routes, capable only of performing middleware and routing functions. A router behaves like middleware itself, so you can use it as an argument to app.use() or as the argument to another routerโ€™s use() method. Every Express application has a built-in app router:
  • 19. Chainable route handlers for a route path can be created using app.route(). Since the path is specified at a single location, it helps to create modular routes and reduce redundancy and typos.
  • 20. The express.Router class can be used to create modular mountable route handlers. A Router instance is a complete middleware and routing system; for this reason it is often referred to as a โ€œmini-appโ€ And then
  • 21. Middleware is the core concept behind Express.js request processing and routing and is composed from any number of functions that are invoked by the Express.js routing layer before final application request handler is invoked. ๏‚ง Application-level middleware ๏‚ง Router-level middleware ๏‚ง Error-handling middleware ๏‚ง Built-in middleware ๏‚ง Third-party middleware Middleware function signature is simple:
  • 22. Express.js has great built in capabilities to serve static content. The module is able to also gzip compress and/or cache served files, tooโ€ฆ *As of 4.x, all of Express' previously included middleware are now in separate repositories. The only included middleware is: express.static(), used to server static files.
  • 23. Error-handling middleware are defined just like regular middleware, however must be defined with an arity of 4 signature: (error, request, response, next)
  • 24. error-handling middleware are typically defined very last, below any other app.use() calls...
  • 25. All of Express' previously (before v4.0) included middleware are now in separate repos. Here are some example middleware modules: ๏‚ง body-parser ๏‚ง compression ๏‚ง connect-timeout ๏‚ง csurf ๏‚ง errorhandler ๏‚ง method-override ๏‚ง morgan - previously logger ๏‚ง response-time ๏‚ง serve-favicon
  • 26. ๏‚ง Koa Koa is designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs. Through leveraging generators Koa allows you to ditch callbacks and greatly increase error-handling ๏‚ง Restify restify is a node.js module built specifically to enable you to build correct REST web services. It intentionally borrows heavily from express as that is more or less the de facto API for writing web applications on top of node.js. ๏‚ง Hapi hapi is a simple to use configuration-centric framework with built-in support for input validation, caching, authentication, and other essential facilities for building web and services applications.
  • 27. ๏‚ง Hypermedia driven? ๏‚ง Media types? ๏‚ง Uniform interface? ๏‚ง Stateless?
  • 28. ๏‚ง Hypermedia driven? ๏‚ง Media types? http://events.layer7tech.com/state-api ๏‚ง Stateless? ๏‚ง Uniform interface?
  • 30. Generic: text/html application/xml application/json Generic with hypermedia elements: application/hal+json application/json-ld Domain Specific: application/vnd.mymediatype-v2+json Media Types define: 1. How is byte stream encoded and how to locate hypermedia elements 2. What the data represents Format: typeโ€/โ€subtype *(โ€œ;โ€ parameter) Used in: โ€œAcceptโ€ and โ€œContentTypeโ€ headers
  • 31. Avoid generic media types (like JSON and XML) - they do not include hypermedia elements Choice: 1) Use few (one?) generic media types with hypermedia elements ( to avoid the need for clients to understand too many ) + the domain specific media types identified by a profile โ€“ in the payload or in a HTTP header or 2) Use many different domain specific media types?
  • 32. HAL is designed for building APIs in which clients navigate around the resources by following links. Links are identified by link relations, the lifeblood of a hypermedia API: they are how you tell client developers about what resources are available and how they can be interacted with, and they are how the code they write will select which link to traverse HAL - Specification
  • 33. The architectural properties affected by the constraints of the REST architectural style are:[4][6] - Performance - component interactions can be the dominant factor in user-perceived performance and network efficiency.[7] - Scalability to support large numbers of components and interactions among components. Roy Fielding, one of the principal authors of the HTTP specification, describes REST's effect on scalability thus: REST's clientโ€“server separation of concerns simplifies component implementation, reduces the complexity of connector semantics, improves the effectiveness of performance tuning, and increases the scalability of pure server components. Layered system constraints allow intermediariesโ€”proxies, gateways, and firewallsโ€”to be introduced at various points in the communication without changing the interfaces between components, thus allowing them to assist in communication translation or improve performance via large-scale, shared caching. REST enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to indicate semantics and exchange information, and responses explicitly indicate cacheability.[4] Simplicity of interfaces Modifiability of components to meet changing needs (even while the application is running) Visibility of communication between components by service agents Portability of components by moving program code with the data Reliability is the resistance to failure at the system level in the presence of failures within components, connectors, or data[7]
  • 34. ๏‚ง Uniform Interface ๏‚ง Stateless ๏‚ง Cacheable ๏‚ง Client-Server ๏‚ง Layered System ๏‚ง Code on Demand (optional)
  • 35. The uniform interface constraint defines the interface between clients and servers. It simplifies and decouples the architecture and enables each part to evolve independently. The four guiding principles of the uniform interface are: ๏‚ง Resource-Based Individual resources are identified in requests using URIs as resource identifiers. The resources themselves are conceptually separate from the representations that are returned to the client ๏‚ง Manipulation of Resources Through Representations When a client holds a representation of a resource, including any metadata attached, it has enough information to modify or delete the resource on the server, provided it has permission to do so ๏‚ง Self-descriptive Messages Each message includes enough information to describe how to process the message. For example, which parser to invoke may be specified by an Internet media type (previously known as a MIME type) ๏‚ง Hypermedia as the Engine of Application State (HATEOAS) HATEOS is the key constrain that makes web browsing possible. Applicable to APIs but not widely used. It is simple to understand: each response message includes the links to next possible request message.
  • 36. As REST is an acronym for REpresentational State Transfer, server statelessness is key. Essentially, what this means is that the necessary state to handle the request is contained within the request itself, whether as part of the URI, query-string parameters, body, or headers Clients handle application state, servers resource state Application state is information about where you are in the interaction that is used during your session with an application. Resource state is the kind of (semi-)permanent data a server stores, and lasts beyond the duration of a single session of interactions.
  • 37. The goal of caching is never having to generate the same response twice. The benefit of doing this is that we gain speed and reduce server load. ๏‚ง Expiration ๏‚ง Expires header ๏‚ง Cache-Control header ๏‚ง Validation ๏‚ง Last-Modified header ๏‚ง ETag header
  • 38. The client-server constraint is based on a principle known as the separation of concerns. It simply requires the existence of a client component that sends requests and a server component that receives requests Servers and clients may also be replaced and developed independently, as long as the interface is not altered
  • 39. REST architecture is conceived as hierarchical layers of components, limited to communication with their immediate neighbors. A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way.
  • 40. The optional code-on-demand constraint allows clients to request and execute code from servers. This, in turn, allows the server to deploy new features to clients. The result is improved extensibility and configurability for servers, and improved performance and efficiency for clients
  • 41. Level 0: Swamp of POX tunnels requests and responses through its transport protocol, using only one entry point (URI) and one kind of method (in HTTP, this normally is the POST method). Examples of these are SOAP and XML-RPC/JSON/RPC. Level 1: Resources This level uses multiple URIs, where every URI is the entry point to a specific resource. Still, this level uses only one single method like POST. Level 2: (HTTP) verbs This level suggests that in order to be truly RESTful, your API MUST use limited set of verbs. Level 3: Hypermedia controls Level 3, the highest level, uses HATEOAS to deal with discovering the possibilities of your API towards the clients.
  • 42. ๏‚ง Granular (leads to CRUD) ๏‚ง Not scalable ๏‚ง Low level ๏‚ง Chatty ๏‚ง Business logic moves to consumer ๏‚ง Coarse grained ๏‚ง Focus on business entities vs activities ๏‚ง Decoupled from internal domain implementation ๏‚ง Business logic contained on th eserver side *Use only GET and POST (CQRS)?
  • 44. This presentation on GitHub: Building Killer RESTful APIs Node.Js ๏‚ง Mixu Online book ๏‚ง Why Asynchronous? ๏‚ง Mastering Node Express ๏‚ง Express Home Page ๏‚ง Understanding Express.js ๏‚ง A short guide to Connect Middleware REST APIs ๏‚ง REST API Tutorial ๏‚ง Restful Exploration ๏‚ง HAL - Hypertext Application Language