Simple Restful Api (get) without db Connection ( Node Js + Express)

This sample will show you that how simple nodejs http restful API is working

first test is returning array json data

second and Third is just restun json data


======== sample source ===========


var express = require('express');
var app = express();
app.get('/school', function(req,res){
    res.send([{bus:'bus1'}, {bus:'bus2'}]);
});


app.get('/school/:number', function(req, res){
    res.send({id:'two path', number:req.params.number});
});

app.get('/school/:number/:destination', function(req, res){
    res.send({id:'three path', destination:req.params.destination});
})

app.listen(3000);
console.log('Listen on port 3000......');


and result list


1.  http://192.168.123.165:3000/school

[
{
"bus": "bus1"
},
{
"bus": "bus2"
}
]

2. http://192.168.123.165:3000/school/second
{
"id": "two path",
"number": "second"
}

3. http://192.168.123.165:3000/school/third
{
"id": "three path",
"destination": "third"
}

Comments

Popular posts from this blog

Project euler 169 found clue

Floyd-Warshall's algorithm