import requests
import json


def get_routes(switchuser, switchpassword, url):
    """
    Here's a function that takes in a common set of information, does one thing and then returns the result.

    :param switchuser: A string that contains the username to access the device
    :param switchpassword: A string that contains the password for the given username
    :param url: The URL to reach the NXAPI
    :return: A python dictionary containing the response from the NXAPI

    """

    # These variables are scoped locally to this function only. If you tried to access it outside of the function
    # then you would get an error!
    myheaders = {'content-type': 'application/json'}
    payload = {
      "ins_api": {
        "version": "1.0",
        "type": "cli_show",
        "chunk": "0",
        "sid": "1",
        "input": "show ip route",
        "output_format": "json"
      }
    }

    # Just like before we'll go ahead and make our request. We'll just use the exact output from the API sandbox
    response = requests.post(url,
                             data=json.dumps(payload),
                             headers=myheaders,
                             auth=(switchuser, switchpassword)).json()

    # If we want this function to send out the results for use elsewhere then we have to return it
    return response