def strip_api(server_url):
    """
    Strips "api/" from the end of ``server_url``, if present

    >>> strip_api('https://play.dhis2.org/demo/api/')
    'https://play.dhis2.org/demo/'

    """
    if server_url.rstrip('/').endswith('api'):
        i = len(server_url.rstrip('/')) - 3
        return server_url[:i]
    return server_url