async refreshAccessToken() { const { data } = await axios({ baseURL: this.localApiUrl, url: '/api/v1/access_token', method: 'post', data: { refresh_token: this.session.getRefreshToken() } }); this.session.setAccessToken(data.access_token); }
async function request(options) { if (typeof options === 'string') { options = { url: options, }; } if (!options.method) { options.method = 'get'; } const result = await axios(options); if (!result) { return undefined; } return result.data; }
async uploadFromStreamURL(url: string, pathname: string): Promise<string> { const client = new OSS({ region: this.configService.aliyunOSS.region, accessKeyId: this.configService.aliyunOSS.accessKeyID, accessKeySecret: this.configService.aliyunOSS.accessKeySecret, bucket: this.configService.aliyunOSS.bucket, }); const res = await axios({ method: 'get', url, responseType: 'stream', }); const uploadName = `${this.configService.aliyunOSS.uploadPrefix}${pathname}`; const result = await client.putStream(uploadName, res.data.pipe(new PassThrough())); let name = result.name || ''; if (name.charAt(0) !== '/') { name = '/' + name; } return this.configService.static.uploadImgURL + name; }
async executeQuery(method, url, query, body, retryCount = 0) { if (retryCount > MAX_RETRY) { this.session.reset(); throw new Error('MAX_RETRY_EXCEEDED'); } try { const { data } = await axios({ baseURL: this.localApiUrl, url, method, params: query, data: body, headers: this.getAxiosHeaders() }); return data; } catch (e) { if (e.response && e.response.status === 401) { await this.refreshAccessToken(); return this.executeQuery(method, url, query, body, retryCount + 1); } throw e; } }
async getIssues({ org, repo, labels, ignoreLabels = [] }) { const config = { method: 'POST', url: 'https://api.github.com/graphql', headers: { Authorization: `Bearer ${process.env.GitHubToken}`, 'Content-Type': 'application/json'} }; if (!!labels) { const issues = await labels.reduce(async (result, label) => { const query = this.getQuery(`repo:${org}/${repo} is:open is:issue label:${label} ${ignoreLabels.map(ignore => `-label:'${ignore}'`).join(' ')}`); const response = await axios({...config, data: query }); if (response.data && response.data.errors && response.data.errors.length > 0) { this.context.error(JSON.stringify(response.data.errors, null, 2)); return; } const { data: { data: { search: { edges: issues }}}} = response; if (issues.length > 0) { result.push(issues); } return result; }, []); return issues; } else { const query = this.getQuery(`repo:${org}/${repo} is:issue ${ignoreLabels.map(ignore => `-label:${ignore}`).join(' ')}`); const { data: { data: { search: { edges: issues }}}} = await axios({...config, data: query }); return issues; } }
axios({ method: 'post', url: 'https://slack.com/api/chat.postMessage',
states.splice(states.indexOf(state), 1); try { const { status, data } = await axios({ method: 'POST', url: `https://${githubUrl}/login/oauth/access_token`,
async componentDidMount() { try { let search = this.props.location.search, id = search.substring(1, search.length); const updateUser = await axios(`/api/users/${id}`); const { name, genre, age } = updateUser.data.user; this.setState({ id, name, genre, age }); } catch (err) { this.setState({ response: "User not found!" }) } }
const requestHandler = (method, url, data, headers) => { const config = { method, url, data, headers } return axios(config).then((response) => response.data) .catch((error) => (error.response ? error.response.data : error.response)) }
async getLatestGladysVersion(currentGladysVersion, params) { const { data } = await axios({ method: 'GET', baseURL: this.serverUrl, url: '/v1/api/gladys/version', params, headers: { 'user-agent': `Gladys/${currentGladysVersion}`, }, }); return data; }
axios(Server.getRestAPIHost() + '/admin/owner?car=' + car) .then((response) => { let carInfo = response.data; //{"colour":"red","make":"Ford","model":"Mustang","owner":"Brad"} console.log('getOwner:' + carInfo.owner); return carInfo.owner; })
static async getNotices(params) { const { startTime, size } = params; const config = { headers: { "Content-Type": "application/json", }, method: "get", url: `//service.xxoo521.com/apis/notice?startTime=${startTime}&size=${size}`, }; const axiosRes = await axios(config); return axiosRes.data.result; }
const call = method => (url, { body, query, headers } = {}) => { return axios({ method, baseURL: `http://localhost:3003${url}`, data: body, headers, params: query }) .then(response => response.data); }
async refreshAccessToken() { const { data } = await axios({ baseURL: this.localApiUrl, url: '/api/v1/access_token', method: 'post', data: { refresh_token: this.session.getRefreshToken() } }); this.session.setAccessToken(data.access_token); }
async executeQuery(method, url, query, body, retryCount = 0) { if (retryCount > MAX_RETRY) { this.session.reset(); throw new Error('MAX_RETRY_EXCEEDED'); } try { const { data } = await axios({ baseURL: this.localApiUrl, url, method, params: query, data: body, headers: this.getAxiosHeaders() }); return data; } catch (e) { if (e.response && e.response.status === 401) { await this.refreshAccessToken(); return this.executeQuery(method, url, query, body, retryCount + 1); } throw e; } }