-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60a54b6
commit 8f9539b
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |