用于restful api的api操场
django-api-playground的Python项目详细描述
为restful api创建api浏览器的django应用程序。
与任何restful api一起工作。例如,您可以使用此应用程序为基于tastype的api创建api资源管理器。
演示:http://api-playground-demo.hipo.biz
说明
要启动并运行此应用程序,请执行以下步骤:
从PIP安装:
pip install django-api-playground
或来源:
pip install git+git://github.com/Hipo/Django-API-Playground.git
添加到已安装的应用程序:
INSTALLED_APPS =( # ... 'apiplayground', )
安装完成。现在可以定义api模式了。
第一步,创建一个url:
# urls.py from api.playgrounds import ExampleAPIPlayground urlpatterns = patterns('', (r'api-explorer/', include(ExampleAPIPlayground().urls)), )
第二步,为api定义一个子类:
# api/playgrounds.py from apiplayground import APIPlayground class ExampleAPIPlayground(APIPlayground): schema = { "title": "API Playground", "base_url": "http://localhost/api/", "resources": [ { "name": "/feedbacks", "description": "This resource allows you to manage feedbacks.", "endpoints": [ { "method": "GET", "url": "/api/feedbacks/{feedback-id}", "description": "Returns a specific feedback item" }, { "method": "POST", "url": "/api/feedbacks/", "description": "Creates new feedback item", "parameters": [{ "name": "title", "type": "string" }, { "name": "resource", "type": "string" }, { "name": "description", "type": "string" }] } ] }, ] }
就这些。很快就会有更详细的文件。