V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
b244183
V2EX  ›  Python

做网站 API Wrapper 的最佳实践是什么

  •  
  •   b244183 · 2016-02-12 11:43:36 +08:00 · 2969 次点击
    这是一个创建于 2967 天前的主题,其中的信息可能已经有所发展或是发生改变。

    网站返回 json

    目前的写法如下
    先根据网站提供的描述弄出

    class User
    class Message

    之类的

    然后弄一个 dict 存每种返回类型 return_type = {"a": "User", "b": "Message"}

    然后包装下返回return globals()[return_type.get(method_name)](get(method_name))

    感觉还是不够优雅 还有什么别的最佳实践吗

    1 条回复    2016-02-12 12:46:58 +08:00
    TaoAlpha
        1
    TaoAlpha  
       2016-02-12 12:46:58 +08:00
    RESTful. 这里有篇很不错的文章介绍 RESTful API Design 的.
    http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3317 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.