RESTful API with
Node JS and
Express
Agenda
▷ What is API?
▷ Contrasting common types of APIs
▷ What is Node JS and Express?
▷ Installing Express
▷ Coding Session
▷ Q & A
▷ Workshop
1.
What is API?
“An API is a precise specification of
the programming instruction and
standards to access a web based
software or web tool acting as a link
between the programmer and the
application.
What is an API?
▷ Acronym for Application Program
Interface.
▷ Acts as a bridge between the
programmer and application.
▷ Takes specific requests predefined
when created.
▷ Verifies the requests and then processes
the data.
▷ Gives detailed info on what and how the
request are to be made.
REST APIs
▷ REST stands for Representational State Transfer. (ReST)
▷ It is not a framework but Architectural Principle.
▷ Uses HTTP requests which is oriented around verbs and
resources ( GET, POST, PUT, DELETE)
▷ The verbs are applied to resources ( data )
POST something to database.
GET something from Users.
DELETE something from clients.
▷ The request consist of Headers, body and methods.
▷ The response consists of Status Code, Headers and the body.
▷ Caching and Stateless.
▷ Data represented mostly through HTML / XML / JSON.
REST APIs
Contrasting types of APIs
REST
▷ Stands for Representational
State Transfer.
▷ Is an Architectural principle.
▷ Permits different data
formats.
▷ Better Performance and
Scalability.
▷ Supports Caching .
▷ Limited to single HTTP
transaction. Expects user to
retry if something fails.
▷ Used in all type of system
apart from some where high
security risk are present.
SOAP
▷ Stands for Simple Object
Access Protocol.
▷ Is a protocol.
▷ Permits only XML.
▷ Scalable but at a very
minimum level.
▷ Doesn’t support caching.
▷ Can ensure ACID
transactions.
▷ Used mostly in High risk
enterprise softwares and
banking softwares.
About Node.js
Node.js is not a silver-bullet
new platform that will
dominate the web
development world. Instead,
it’s a platform that fills a
particular need
What is challenge in web
development?
Thread handling.
Why Node.JS ?
Open
Source
Non -
Blocking
Large
community
Asynchronous I/O
Blocking&Non-BlockingCode
Blocking Code Example
var fs = require("fs");
var data =
fs.readFileSync('input.txt');
console.log(data.toString());
console.log("Program Ended");
Output
Everything in the file input.txt
Program Ended
Non-Blocking Code Example
var fs = require("fs");
fs.readFile('input.txt', function
(err, data) {
if (err) return
console.error(err);
console.log(data.toString());
});
console.log("Program Ended");
Output
Program Ended
Everything in the file input.txt
BasicExample
var http = require("http");
http.createServer(function(request, response){
response.writeHead(200, {'Content-Type':
'text/html'});
response.end('<h1>Hello World</h1>');
}).listen(1234);
console.log("Server running at port 1234");
ThankYou

Rest api with node js and express

  • 1.
    RESTful API with NodeJS and Express
  • 2.
    Agenda ▷ What isAPI? ▷ Contrasting common types of APIs ▷ What is Node JS and Express? ▷ Installing Express ▷ Coding Session ▷ Q & A ▷ Workshop
  • 3.
  • 4.
    “An API isa precise specification of the programming instruction and standards to access a web based software or web tool acting as a link between the programmer and the application.
  • 5.
    What is anAPI? ▷ Acronym for Application Program Interface. ▷ Acts as a bridge between the programmer and application. ▷ Takes specific requests predefined when created. ▷ Verifies the requests and then processes the data. ▷ Gives detailed info on what and how the request are to be made.
  • 6.
  • 7.
    ▷ REST standsfor Representational State Transfer. (ReST) ▷ It is not a framework but Architectural Principle. ▷ Uses HTTP requests which is oriented around verbs and resources ( GET, POST, PUT, DELETE) ▷ The verbs are applied to resources ( data ) POST something to database. GET something from Users. DELETE something from clients. ▷ The request consist of Headers, body and methods. ▷ The response consists of Status Code, Headers and the body. ▷ Caching and Stateless. ▷ Data represented mostly through HTML / XML / JSON. REST APIs
  • 8.
    Contrasting types ofAPIs REST ▷ Stands for Representational State Transfer. ▷ Is an Architectural principle. ▷ Permits different data formats. ▷ Better Performance and Scalability. ▷ Supports Caching . ▷ Limited to single HTTP transaction. Expects user to retry if something fails. ▷ Used in all type of system apart from some where high security risk are present. SOAP ▷ Stands for Simple Object Access Protocol. ▷ Is a protocol. ▷ Permits only XML. ▷ Scalable but at a very minimum level. ▷ Doesn’t support caching. ▷ Can ensure ACID transactions. ▷ Used mostly in High risk enterprise softwares and banking softwares.
  • 9.
    About Node.js Node.js isnot a silver-bullet new platform that will dominate the web development world. Instead, it’s a platform that fills a particular need
  • 10.
    What is challengein web development? Thread handling.
  • 11.
    Why Node.JS ? Open Source Non- Blocking Large community
  • 12.
  • 13.
    Blocking&Non-BlockingCode Blocking Code Example varfs = require("fs"); var data = fs.readFileSync('input.txt'); console.log(data.toString()); console.log("Program Ended"); Output Everything in the file input.txt Program Ended Non-Blocking Code Example var fs = require("fs"); fs.readFile('input.txt', function (err, data) { if (err) return console.error(err); console.log(data.toString()); }); console.log("Program Ended"); Output Program Ended Everything in the file input.txt
  • 14.
    BasicExample var http =require("http"); http.createServer(function(request, response){ response.writeHead(200, {'Content-Type': 'text/html'}); response.end('<h1>Hello World</h1>'); }).listen(1234); console.log("Server running at port 1234");
  • 16.