Permalink
Browse files

updated readme with agent usage

  • Loading branch information...
1 parent c895bf1 commit 49fc64327aecc5d59903f812b03c5a75f57972d9 @hunterloftis hunterloftis committed Aug 9, 2012
Showing with 26 additions and 10 deletions.
  1. +26 −10 Readme.md
View
@@ -12,15 +12,15 @@
```js
$.get('/user/1', function(data, textStatus, xhr){
-
+
});
```
great, it's ok, but it's kinda lame having 3 arguments just to access something on the `xhr`. Our equivalent would be:
```js
request.get('/user/1', function(res){
-
+
});
```
@@ -35,9 +35,9 @@ $.ajax({
data: { name: 'Manny', species: 'cat' },
headers: { 'X-API-Key': 'foobar' }
}).success(function(res){
-
+
}).error(function(){
-
+
});
```
@@ -50,26 +50,26 @@ request
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end(function(res){
-
+
});
```
building on the existing API internally we also provide something similar to `$.post()` for those times in life where your interactions are very basic:
```js
request.post('/api/pet', cat, function(res){
-
+
});
```
## Running node tests
Install dependencies:
-
+
$ npm install -d
-
+
Run em!
-
+
$ make test
## Running browser tests
@@ -84,11 +84,27 @@ request.post('/api/pet', cat, function(res){
Visit `localhost:3000/` in the browser.
+## Using superagent as a persistent agent (with cookies, ie sessions)
+
+```js
+var request = require('superagent');
+var agent = request.agent();
+agent
+ .post('http://localhost:4000/signin')
+ .send({ user: 'hunter@hunterloftis.com', password: 'password' })
+ .end(function(err, res) {
+ // this Agent will manage a cookie jar, emulating a browser
+ // res.redirects contains an Array of this request's redirects
+ });
+```
+
+For examples, view the [agency tests](blob/master/test/node/agency.js)
+
## Wiki
For superagent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki).
-## License
+## License
(The MIT License)

0 comments on commit 49fc643

Please sign in to comment.