高性能 REST 框架 hug 2.0 发布

这是我看过的唯一一个自带 CLI 支持的 REST 框架,似乎挺有意思的:

import hug
import requests

@hug.local()
@hug.cli()
@hug.get()
def top_post(section: hug.types.one_of(('news', 'newest', 'show'))='news'):
    """Returns the top post from the provided section"""
    content = requests.get('https://news.ycombinator.com/{0}'.format(section)).content
    text = content.decode('utf-8')
    return text.split('<tr class=\'athing\'>')[1].split("<a href")[1].split(">")[1].split("<")[0]

hug 基于 web 框架 Falcon,仅支持 Python 3。

GitHub:https://github.com/timothycrosley/hug

3 comments