rest api with node js and express

Post on 13-Jan-2017

104 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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 communit

y

Asynchronous I/O

Blocking & Non-Blocking CodeBlocking Code Examplevar 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

Basic Example

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");

Thank You

top related