input: Write a function to fetch data from a RESTful API endpoint.
  assert fetch_data('http://example.com/table') == {'data': 'formatted data'}
  assert fetch_data('http://example.com/nonexistent') == {'error': 'Resource not found'}
  assert fetch_data('http://example.com/table', method='POST', data={'key': 'value'}) == {'message': 'Data posted successfully'}
output: import requests
  
  def fetch_data(url, method='GET', data=None):
      try:
          if method == 'GET':
              response = requests.get(url)
          elif method == 'POST':
              response = requests.post(url, json=data)
          else:
              return {'error': 'Unsupported HTTP method'}
  
          response.raise_for_status()
          return response.json()
      except requests.exceptions.HTTPError as http_err:
          if response.status_code == 404:
              return {'error': 'Resource not found'}
          else:
              return {'error': str(http_err)}
      except Exception as err:
          return {'error': str(err)}