src/utils/http.js
function GET(uri, params) {
	const reqUrl = `${uri}${url.format({ query: params })}`;

	log(`request URL: ${reqUrl}`);

	return fetch(reqUrl)
		.then(function handleGetRequest(res) {
			const status = res.status;
			const statusText = res.statusText;

			log(`status code: ${status}`);
			log(`status text: ${statusText}`);

			if (status !== 200) {
				const err = new Error(`Request failed: ${statusText}`);

				err.status = status;

				throw err;
			}

			return res.json();
		})
		.then(data => {
			const posts = data.posts;

			log(`${posts.length} posts were fetched`);

			return posts;
		})
		.catch(err => {
			log('catched err: ', err);

			throw err;
		});
}
function GET(uri, params) {
	const reqUrl = `${uri}${url.format({ query: params })}`;

	log(`request URL: ${reqUrl}`);

	return fetch(reqUrl)
		.then(function handleGetRequest(res) {
			const status = res.status;
			const statusText = res.statusText;

			log(`status code: ${status}`);
			log(`status text: ${statusText}`);

			if (status !== 200) {
				const err = new Error(`Request failed: ${statusText}`);

				err.status = status;

				throw err;
			}

			return res.json();
		})
		.then(data => {
			const posts = data.posts;

			log(`${posts.length} posts were fetched`);

			return posts;
		})
		.catch(err => {
			log('catched err: ', err);

			throw err;
		});
}
function GET ( uri , params ) { const reqUrl = ` ${ uri } ${ url . format ( { query : params } ) } ` ; log ( ` ${ reqUrl } ` ) ; return fetch ( reqUrl ) . then ( function handleGetRequest ( res ) { const status = res . status ; const statusText = res . statusText ; log ( ` ${ status } ` ) ; log ( ` ${ statusText } ` ) ; if ( status !== 200 ) { const err = new Error ( ` ${ statusText } ` ) ; err . status = status ; throw err ; } return res . json ( ) ; } ) . then ( data => { const posts = data . posts ; log ( ` ${ posts . length } ` ) ; return posts ; } ) . catch ( err => { log ( 'catched err: ' , err ) ; throw err ; } ) ; }
Makes an HTTP GET request for a specific URI.

@param {String} uri    - the request URI
@param {Object} params - the request query parameters

@return {Promise} resolves with the HTTP response
Makes an HTTP GET request for a specific URI .