Skip to content

Commit

Permalink
readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
hij1nx committed May 17, 2011
1 parent c3ba0b6 commit 88ee7e0
Showing 1 changed file with 54 additions and 56 deletions.
110 changes: 54 additions & 56 deletions README.md
Expand Up @@ -65,24 +65,24 @@ In most cases you will want to make assertions on the outgoing and incoming data
### Specifying settings that apply to all calls that get made...

```javascript
var porter = Porter({
var porter = Porter({

users: {
list: ['get', '/api/users/:partialname', { out: hasData, in: hasData }],
update: ['post', '/api/apps/:username', { in: hasData }]
},
users: {
list: ['get', '/api/users/:partialname', { out: hasData, in: hasData }],
update: ['post', '/api/apps/:username', { in: hasData }]
},

apps: {
list: ['get', '/api/apps/:username', { in: hasData }],
create: ['post', '/api/apps/:username/:appname', { in: hasData }]
}
apps: {
list: ['get', '/api/apps/:username', { in: hasData }],
create: ['post', '/api/apps/:username/:appname', { in: hasData }]
}

}).use({
port: 8080,
in: fn1,
out: fn2,
headers: { 'Accept': 'application/json' }
});
}).use({
port: 8080,
in: fn1,
out: fn2,
headers: { 'Accept': 'application/json' }
});
```

The `use` function sets the defaults for all calls that get made. It accepts an object literal containing the following members...
Expand All @@ -98,62 +98,60 @@ The `use` function sets the defaults for all calls that get made. It accepts an
And here is the above code in use...

```javascript
porter.headers['Authorization'] = 'Basic ' + encodeBase64('username:password');

porter.users.update(
{ partialname: 'bill' },
{ address: '555 Mockingbird Ln' },
function(error, response) {
console.log(error || response);
}
);
porter.headers['Authorization'] = 'Basic ' + encodeBase64('username:password');

porter.users.update(

{ partialname: 'bill' },
{ address: '555 Mockingbird Ln' },

function(error, response) {
console.log(error || response);
}
);
```

The `update` function was generated from its definition in the `users` group. We pass it a payload object, some data to replace the url tokens with and a callback function for when the request has finished processing. The app object will also expose the headers collection, this is simply an object literal that contains the headers to be used for the request.

### Specifying what to do with the response.

```javascript
var porter = Porter({
var porter = Porter({

users: {
list: ['get', '/api/users/:partialname']
}
users: {
list: ['get', '/api/users/:partialname']
}

}).use({
port: 8080,
host: 'google.com'
}).on({
'500': function(err, response) {
// do something...
},
'404': function(err, response) {
// do something...
}
});
}).use({
port: 8080,
host: 'google.com'
}).on({
'500': function(err, response) {
// do something...
},
'404': function(err, response) {
// do something...
}
});
```

In a lot of cases you'll want to handle http responses based on their response code. using the `on` method will allow you to associate methods with these response codes. In some cases you'll want to explicitly override these http response code handlers. you can do this by replacing the regular callback method with an object literal containing the items to overwrite.

```javascript
porter.headers['Authorization'] = 'Basic ' + encodeBase64('username:password');

porter.users.update(

{ partialname: 'bill' },
{ address: '555 Mockingbird Ln' },

{
'404': function(err, response) {
// do something...
},
'500': function(err, response) {
// do something...
}
porter.users.update(

{ partialname: 'bill' },
{ address: '555 Mockingbird Ln' },

{
'404': function(err, response) {
// do something...
},
'500': function(err, response) {
// do something...
}
);
}
);
```

Porter provides a simple Node.js server to complement it's test suite. You may find this a useful starting point for your own test suite.
Expand Down

0 comments on commit 88ee7e0

Please sign in to comment.