github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/build-blockchain-insurance-app-master/web/src/block-explorer/api.js (about) 1 'use strict'; 2 3 import fetch from 'isomorphic-fetch'; 4 5 export function getBlocksFromShop(noOfLastBlocks) { 6 return getBlocks('/shop/api/blocks', noOfLastBlocks); 7 } 8 9 export function getBlocksFromSelfService(noOfLastBlocks) { 10 return getBlocks('/self-service/api/blocks', noOfLastBlocks); 11 } 12 13 export function getBlocksFromRepairShop(noOfLastBlocks) { 14 return getBlocks('/repair-shop/api/blocks', noOfLastBlocks); 15 } 16 17 export function getBlocksFromContractManagement(noOfLastBlocks) { 18 return getBlocks('/insurance/api/blocks', noOfLastBlocks); 19 } 20 21 function getBlocks(url, noOfLastBlocks) { 22 return fetch(url, { 23 method: 'POST', 24 headers: new Headers({ 25 'Content-Type': 'application/json' 26 }), 27 body: JSON.stringify({ noOfLastBlocks }) 28 }).then(async res => { 29 const blocks = await res.json(); 30 return blocks; 31 }); 32 }