import requests


def sendRequest(url, type="POST", params=None, headers=None):
    """
    Send a request to a URL

    ### Input:
        - `url`                     (str)   | the url to send the request to
        - `type`                    (str)   | the type of request (GET or POST)
        - `params`                  (dict)  | parameters to be sent with the request
        - `headers`                 (dict)  | headers to be sent with the request
    
    ### Output:
        - `response`                (dict)  | the JSON response of the request
    """

    ## Perform a GET request
    if type == "GET":
        rawResponse = requests.get(url, params=params, headers=headers)
    ## Perform a POST request
    else:
        rawResponse = requests.post(url, params=params, headers=headers)

    ## Convert the response to a json object, if possible
    if hasattr(rawResponse, "json"):
        response = rawResponse.json()
    ## Otherwise, get the text response
    else:
        response = rawResponse.text

    return response