2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

docs: es6ify the docs a little (#1461)

This commit is contained in:
Justin Beckwith
2018-04-08 00:18:56 -07:00
committed by GitHub
parent 7b11cc7181
commit 8e3b50c564
2 changed files with 34 additions and 35 deletions
+22 -23
View File
@@ -11,12 +11,12 @@ $ npm install axios promise --save
```
```js
var axios = require('axios');
const axios = require('axios');
require('promise/polyfill-done');
axios
.get('http://www.example.com/user')
.then(function (response) {
.then((response) => {
console.log(response.data);
return response;
})
@@ -30,16 +30,16 @@ $ npm install axios promise.prototype.finally --save
```
```js
var axios = require('axios');
const axios = require('axios');
require('promise.prototype.finally').shim();
axios
.get('http://www.example.com/user')
.then(function (response) {
.then((response) => {
console.log(response.data);
return response;
})
.finally(function () {
.finally(() => {
console.log('this will always be called');
});
```
@@ -52,19 +52,19 @@ $ npm install axios pako --save
```js
// client.js
var axios = require('axios');
var pako = require('pako');
const axios = require('axios');
const pako = require('pako');
var user = {
const user = {
firstName: 'Fred',
lastName: 'Flintstone'
};
var data = pako.deflate(JSON.stringify(user), { to: 'string' });
const data = pako.deflate(JSON.stringify(user), { to: 'string' });
axios
.post('http://127.0.0.1:3333/user', data)
.then(function (response) {
.then((response) => {
response.data = JSON.parse(pako.inflate(response.data, { to: 'string' }));
console.log(response.data);
return response;
@@ -73,25 +73,24 @@ axios
```js
// server.js
var pako = require('pako');
var http = require('http');
var url = require('url');
var server;
const pako = require('pako');
const http = require('http');
const url = require('url');
server = http.createServer(function (req, res) {
const server = http.createServer((req, res) => {
req.setEncoding('utf8');
var parsed = url.parse(req.url, true);
var pathname = parsed.pathname;
const parsed = url.parse(req.url, true);
const pathname = parsed.pathname;
if (pathname === '/user') {
var data = '';
req.on('data', function (chunk) {
let data = '';
req.on('data', (chunk) => {
data += chunk;
});
req.on('end', function () {
var user = JSON.parse(pako.inflate(data, { to: 'string' }));
req.on('end', () => {
const user = JSON.parse(pako.inflate(data, { to: 'string' }));
console.log(user);
res.writeHead(200, {
@@ -115,9 +114,9 @@ $ npm install jsonp --save
```
```js
var jsonp = require('jsonp');
const jsonp = require('jsonp');
jsonp('http://www.example.com/foo', null, function (err, data) {
jsonp('http://www.example.com/foo', null, (err, data) => {
if (err) {
console.error(err.message);
} else {