基于django的rest api框架
rinzler的Python项目详细描述
#rinzler-rest框架
;安装需要
``php
``php
pip install rinzler
```
`
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `使用
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `控制器导入控制器
base廑dir=os.path.dirname(os.path.dirname(os.path.abspath(廑file廑))
assembler=app['url廑assembler']
urlpatterns=[
assembler.mount('hello',controller),
assembler.mount(''',maincontroller),
]
````
```python
app):
router=app['router']
app:dict(),**param s:dict):
“
默认路由回调
:param request httprequest
:param app rinzler's object
:param params dict url params,如果存在,请尝试:
:rtype:response
“
尝试:
response=ordereddict()
response[“status”]=true
response[“data”]=“Hello World!”
返回响应(response,content\u type=“application/json”)
基本异常除外,例如e:
response=orderedict()
response[“status”]=false
response[“mensagem”]=str(e)
返回响应(response,content\u type=“application/json”,status=500)\
@staticmethod
def hello_用户(请求:httprequest,app:dict(),**param s:dict):
“
默认路由回调
:param request httprequest
:param app rinzler的对象
:param params dict url params,如果存在
:rtype:response
”“
”请尝试:
user=params['name]
response=ordereddict()
response[“status”]=true
response[“data”]=“您好{0}!”.format(user)
return response(response,content_type=“application/json”)
除了baseexception,例如e:
response=ordereddict()
response[“status”]=false
response[“mensage”]=str(e)
return response(response,content_type=“application/json”,状态=500)
````
``python manage.py runserver
2017年8月2日-18:48:00
django版本1.10.4,使用设置“demo.settings”
在http://127.0.0.1:8000启动开发服务器/
使用control-c退出服务器。
````
```shell
curl http://localhost:8000/
<;center>;<;h1>;http/1.1200 ok rinzler framework<;/h1>;<;/center>;
curl http://localhost:8000/hello/world/
{
“status”:true,
“data”:“hello world!”
}
{
“status”:true,
“data”:“hello bob!”
}
curl http://localhost:8000/foo/bar/
{
“status”:false,
“exceptions”:{
“message”:“找不到get foo/bar/”
},
“request”:{
“content”:,
“method”:“get”,
“path-info”:“foo/bar/”
“message”:“很抱歉,但是出了严重的问题。
;安装需要
``php
``php
pip install rinzler
```
`
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `使用
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `控制器导入控制器
base廑dir=os.path.dirname(os.path.dirname(os.path.abspath(廑file廑))
urlpatterns=[
assembler.mount('hello',controller),
assembler.mount(''',maincontroller),
]
````
```python
app):
router=app['router']
app:dict(),**param s:dict):
“
默认路由回调
:param request httprequest
:param app rinzler's object
:param params dict url params,如果存在,请尝试:
:rtype:response
“
尝试:
response=ordereddict()
response[“status”]=true
response[“data”]=“Hello World!”
返回响应(response,content\u type=“application/json”)
基本异常除外,例如e:
response=orderedict()
response[“status”]=false
response[“mensagem”]=str(e)
返回响应(response,content\u type=“application/json”,status=500)\
@staticmethod
def hello_用户(请求:httprequest,app:dict(),**param s:dict):
“
默认路由回调
:param request httprequest
:param app rinzler的对象
:param params dict url params,如果存在
:rtype:response
”“
”请尝试:
user=params['name]
response=ordereddict()
response[“status”]=true
response[“data”]=“您好{0}!”.format(user)
return response(response,content_type=“application/json”)
除了baseexception,例如e:
response=ordereddict()
response[“status”]=false
response[“mensage”]=str(e)
return response(response,content_type=“application/json”,状态=500)
````
``python manage.py runserver
2017年8月2日-18:48:00
django版本1.10.4,使用设置“demo.settings”
在http://127.0.0.1:8000启动开发服务器/
使用control-c退出服务器。
````
```shell
curl http://localhost:8000/
<;center>;<;h1>;http/1.1200 ok rinzler framework<;/h1>;<;/center>;
curl http://localhost:8000/hello/world/
{
“status”:true,
“data”:“hello world!”
}
“status”:true,
“data”:“hello bob!”
}
curl http://localhost:8000/foo/bar/
{
“status”:false,
“exceptions”:{
“message”:“找不到get foo/bar/”
},
“request”:{
“content”:,
“method”:“get”,
“path-info”:“foo/bar/”
“message”:“很抱歉,但是出了严重的问题。