@api_view(['POST'])
def shorten(request, format=None):
    raw_url = request.data.get('url')
    if (not raw_url):
        return JsonResponse(status=400, data={'error': 'missing url parameter'})
    try:
        url = URL.parse(raw_url)
    except ModelValidationError as e:
        return JsonResponse(status=400, data={'error': 'invalid URL', 'details': e.message})
    key = _store_url_and_get_key(url)
    return JsonResponse(status=200, data={'key': key})
@api_view(['POST'])
def shorten(request, format=None):
    raw_url = request.data.get('url')
    if (not raw_url):
        return JsonResponse(status=400, data={'error': 'missing url parameter'})
    try:
        url = URL.parse(raw_url)
    except ModelValidationError as e:
        return JsonResponse(status=400, data={'error': 'invalid URL', 'details': e.message})
    key = _store_url_and_get_key(url)
    return JsonResponse(status=200, data={'key': key})