def upsert_resource(apiroot, settings):

    """

    Convenience function to create or update a resource

    Args:
        apiroot (obj): API endpoint root eg `api.cnxn.pipes`
        settings (dict): resource settings

    Returns:
        response (obj): server response
        data (dict): json returned by server

    """

    try:
        r, d = apiroot._(settings['name']).patch(request_body=settings)
    except Exception as e:
        if 'Not found' in str(e):
            return apiroot.post(request_body=settings)
        else:
            raise e
    return apiroot._(settings['name']).get()