async manifestJSON() { const response = await fetch( `https://api.github.com/repos/${this.repo.owner}/${this.repo.name}/contents/manifest.json` ); return JSON.parse(Buffer.from((await response.json()).content, 'base64').toString()); }
const processJob = async () => { debug('pinging compose to start on-demand db backup'); const result = await compose( `2016-07/deployments/${COMPOSE_DEPLOYMENT_ID}/backups`, { method: 'POST', } ); const json = await result.json(); debug(json); return; }
if (error === undefined || error.code === rateLimitErrorCode.toString()) { let response = await fetch(url, {method: 'POST', headers, body: JSON.stringify(app)}) messageData = await response.json()
try { const response = await fetch(url, {method: 'GET', headers}) messageData = await response.json() break } catch (e) {
if (error === undefined || error.code === rateLimitErrorCode.toString()) { let response = await fetch(url, {method: 'POST', headers, body: JSON.stringify(currentApp)}) messageData = await response.json()
delete(url, body) { return fetch(url, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(body), }) .then(response => response.json()) .then(res => this.constructor.handleError(res)); }
requestAssets(query) { const url = this.buildURL(query, 12); this.setState({ loading: true }) fetch(url) .then(res => res.json()) .then(json => this.setState({ data: json.data, loading: false })) .catch(err => console.log(err)); }
async function getGithubId (accessToken) { const response = await fetch('https://api.github.com/user', { headers: { Authorization: `token ${accessToken}`, Accept: 'application/json' } }) if (response.status !== 200) { throw Error(`getGithubId ${response.status} ${accessToken}`) } const { id: githubId } = await response.json() return githubId }
export function getRecipes (data) { return dispatch => { RecipeModel.getRecipes(data) .then(res => res.json()) .then(json => { dispatch({ type: ApiConstants.GET_RECIPES_SUCCESS, data: json }); }) .catch(err => { dispatch({ type: ApiConstants.GET_RECIPES_ERROR, data: err }) }) } }
const fetchResource = async (resourcePath, params) => { const res = await fetch(buildServiceUrl(resourcePath, params), { headers: { Accept: `application/json` } }) // TODO: Mutate resp.body to hold read JSON and pass along all of res object. return await res.json() }
componentDidMount () { return fetch( 'https://jsonplaceholder.typicode.com/posts' ) .then( resp => resp.json() ) .then( posts => this.setState( { posts } ) ) }
const fetchItems = () => { return dispatch => { dispatch(itemsRequest()); return fetch('http://example.com/items') .then(response => response.json()) .then(json => dispatch(itemsResponse({items: ['classes', 'books']}))) .catch(error => dispatch(itemsError('something went wrong'))) } }
function fetchNews(){ return fetch(`http://newsapi.org/v1/articles?source=google-news&sortBy=top&apiKey=`+apiKey) .then(res => res.json()) .then(json => { // console.log(json) return json }) .catch(err => console.log(err)) }