<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def extras(request):
 """Return a dict with archive metadata for webview."""

    key = request.matchdict.get('key', '').lstrip('/')
    key_map = {
        'languages': _get_available_languages_and_count,
        'subjects': _get_subject_list,
        'featured': _get_featured_links,
        'messages': _get_service_state_messages,
        'licenses': _get_licenses
        }

    with db_connect() as db_connection:
        with db_connection.cursor() as cursor:
            if key:
                proc = key_map[key]
                metadata = {key: proc(cursor)}
            else:
                metadata = {key: proc(cursor)
                            for (key, proc) in key_map.items()}

    resp = request.response
    resp.status = '200 OK'
    resp.content_type = 'application/json'
    resp.body = json.dumps(metadata)
    return resp