Skip to content

Commit

Permalink
docs: example of cookie handling
Browse files Browse the repository at this point in the history
fixes #79
  • Loading branch information
analog-nico committed May 8, 2017
1 parent 9ad707c commit d65ff13
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Expand Up @@ -146,7 +146,7 @@ var options = {
some: 'payload' // Will be urlencoded
},
headers: {
/* 'content-type': 'application/x-www-form-urlencoded' */ // Set automatically
/* 'content-type': 'application/x-www-form-urlencoded' */ // Is set automatically
}
};

Expand All @@ -159,6 +159,39 @@ rp(options)
});
```

### Include a cookie

``` js
var tough = require('tough-cookie');

// Easy creation of the cookie - see tough-cookie docs for details
let cookie = new tough.Cookie({
key: "some_key",
value: "some_value",
domain: 'api.mydomain.com',
httpOnly: true,
maxAge: 31536000
});

// Put cookie in an jar which can be used across multiple requests
var cookiejar = rp.jar();
cookiejar.setCookie(cookie, 'https://api.mydomain.com');
// ...all requests to https://api.mydomain.com will include the cookie

var options = {
uri: 'https://api.mydomain.com/...',
jar: cookiejar // Tells rp to include cookies in jar that match uri
};

rp(options)
.then(function (body) {
// Request succeeded...
})
.catch(function (err) {
// Request failed...
});
```

### Get the full response instead of just the body

``` js
Expand Down

0 comments on commit d65ff13

Please sign in to comment.