-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved plugins to their own repo, changed the before and after events …
…to use a formal event object so that events are preventable and stoppable and added some tests
- Loading branch information
James Newell
committed
Feb 3, 2015
1 parent
2d75554
commit f099452
Showing
11 changed files
with
434 additions
and
293 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
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
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
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,17 @@ | ||
var fs = require('fs'); | ||
var Client = require('..'); | ||
var body = require('go-fetch-body-parser'); | ||
|
||
Client() | ||
.use(body()) | ||
.post('http://httpbin.org/post', {'Content-Type': 'text/x-markdown'}, fs.createReadStream(__dirname+'/../README.md'), function(error, response) { | ||
|
||
console.log( | ||
'Error: '+(error ? error : 'no error')+'\n'+ | ||
'Status: '+response.getStatus()+'\n'+ | ||
'Headers: '+JSON.stringify(response.getHeaders()).substr(0, 100)+'...'+'\n', | ||
response.getBody() | ||
); | ||
|
||
}) | ||
; |
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,27 @@ | ||
var Client = require('..'); | ||
var body = require('go-fetch-body-parser'); | ||
|
||
Client() | ||
.use(function(client) { | ||
client.on('before', function(event) { | ||
event.preventDefault(); | ||
event.response | ||
.setStatus(201) | ||
.setHeader('Content-Type', 'application/json; charset=utf-8') | ||
.setBody(JSON.stringify({ | ||
message: 'Hello World!' | ||
})) | ||
; | ||
}) | ||
}) | ||
.get('http://api.myservice.io', function(error, response) { | ||
|
||
console.log( | ||
'Error: '+(error ? error : 'no error')+'\n'+ | ||
'Status: '+response.getStatus()+'\n'+ | ||
'Headers: '+JSON.stringify(response.getHeaders()).substr(0, 100)+'...'+'\n'+ | ||
(response.getBody() ? response.getBody().substr(0, 100)+'...' : '') | ||
); | ||
|
||
}) | ||
; |
Oops, something went wrong.