Browse Source

add OAuth example to readme (#219) (#221)

node-7
tcme 8 years ago
committed by Sindre Sorhus
parent
commit
7ed62b1e78
  1. 32
      readme.md

32
readme.md

@ -233,7 +233,7 @@ got('google.com', {
## Form data
You can use the [`form-data`](https://www.npmjs.com/package/form-data) module to create POST request with form data:
You can use the [`form-data`](https://github.com/form-data/form-data) module to create POST request with form data:
```js
const fs = require('fs');
@ -250,6 +250,36 @@ got.post('google.com', {
```
## OAuth
You can use the [`oauth-1.0a`](https://github.com/ddo/oauth-1.0a) module to create a signed OAuth request:
```js
const got = require('got');
const OAuth = require('oauth-1.0a');
const oauth = OAuth({
consumer: {
public: process.env.CONSUMER_KEY,
secret: process.env.CONSUMER_SECRET
},
signature_method: 'HMAC-SHA1'
});
const token = {
public: process.env.ACCESS_TOKEN,
secret: process.env.ACCESS_TOKEN_SECRET
};
const url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
got(url, {
headers: oauth.toHeader(oauth.authorize({url, method: 'GET'}, token)),
json: true
});
```
## Unix Domain Sockets
Requests can also be sent via [unix domain sockets](http://serverfault.com/questions/124517/whats-the-difference-between-unix-socket-and-tcp-ip-socket). Use the following URL scheme: `PROTOCOL://unix:SOCKET:PATH`.

Loading…
Cancel
Save