Skip to content

Commit

Permalink
inital restify http patch example
Browse files Browse the repository at this point in the history
  • Loading branch information
mitemitreski committed Jun 2, 2013
1 parent 60a54b6 commit 8f9539b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
15 changes: 15 additions & 0 deletions restify-http-patch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
5 changes: 5 additions & 0 deletions restify-http-patch/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;(function(){
$.getJSON('http://localhost:8080/hi/1', function(data) {
$('#say').text(data.say);
});
}())
14 changes: 14 additions & 0 deletions restify-http-patch/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTTP PATCH example</title>
</head>
<body>
Hello <div id="data">loading</div>
<hr/>
Say <div id="say">No</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="example.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions restify-http-patch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name" : "http-patch-example",
"description" : "example on http patch",
"dependencies" : ["restify"],
"author" : "Mite Mitreski",
"main" : "http-patch",
"version" : "0.0.1"
}
47 changes: 47 additions & 0 deletions restify-http-patch/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var restify = require('restify');

var hello = [{
'id':'0',
'hello': 'world',
'say':'what'
},{
'id':'1',
'say':'what',
'hello': 'it is'
}];


function addHeaders(req, res, next) {
console.log('adding headers');
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
return next();
};

function logRequest(req, res, next){
console.log("Got HTTP " + req.method + " on " + req.url + " responding");
return next();
}

var server = restify.createServer();

server.get('hi', logRequest, addHeaders, function(req, res, next) {
res.send(hello);
return next();
});

server.get('hi/:id', logRequest, addHeaders, function(req, res, next){
res.send(hello[req.params.id]);
return next();
});

server.patch('hi/:id',logRequest, addHeaders, function(req, res, next){
var theObject = hello[req.params.id];
res.send(hello[req.params.id]);
return next();
});


server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});

0 comments on commit 8f9539b

Please sign in to comment.