子集 | 完整表格 | 示例 |
URL | 统一资源定位器 | http://www.gmail.com/ |
URN | 统一资源名称 | urn:isbn:0-201-71088-9 urn:uuid:13e8cf26-2a25-11db-8693-000ae4ea7d46 |
def authenticate(): if not hasattr(cherrypy.request, 'user') or cherrypy.request.user is None: # < do stuff to look up your users > cherrypy.request.authorized = false # this only authenticates. Authz must be handled separately. cherrypy.request.unauthorized_reasons = [] cherrypy.request.authorization_queries = [] cherrypy.tools.authenticate = \ cherrypy.Tool('before_handler', authenticate, priority=10)
def authorize_all(): cherrypy.request.authorized = 'authorize_all' cherrypy.tools.authorize_all = cherrypy.Tool('before_handler', authorize_all, priority=11) def is_authorized(): if not cherrypy.request.authorized: raise cherrypy.HTTPError("403 Forbidden", ','.join(cherrypy.request.unauthorized_reasons)) cherrypy.tools.is_authorized = cherrypy.Tool('before_handler', is_authorized, priority = 49) cherrypy.config.update({ 'tools.is_authorized.on': true, 'tools.authorize_all.on': true })
import cherrypy import json def error_page_default(status, message, traceback, version): ret = { 'status': status, 'version': version, 'message': [message], 'traceback': traceback } return json.dumps(ret) class Root: _cp_config = {'error_page.default': error_page_default} @cherrypy.expose def index(self): raise cherrypy.HTTPError(500, "Internal Sever Error") cherrypy.quickstart(Root())
S.No | HTTP 方法和操作 |
1. |
HEAD
检索资源元数据。
|
2. |
GET
检索资源元数据和内容。
|
3. |
POST
请求服务器使用请求正文中包含的数据创建新资源。
|
4. |
PUT
请求服务器用请求正文中包含的资源替换现有资源。
|
5. |
DELETE
请求服务器删除由该 URI 标识的资源。
|
6. |
OPTIONS
请求服务器返回有关全局或特定资源的功能的详细信息。
|
<?xml version = "1.0" encoding = "UTF-8"?> <service xmlns = "http://purl.org/atom/app#" xmlns:atom = "http://www.w3.org/2005/Atom"> <workspace> <collection href = "http://host/service/atompub/album/"> <atom:title> Albums</atom:title> <categories fixed = "yes"> <atom:category term = "friends" /> </categories> </collection> <collection href = "http://host/service/atompub/film/"> <atom:title>Films</atom:title> <accept>image/png,image/jpeg</accept> </collection> </workspace> </service>
操作 | HTTP 方法 | 状态码 | 内容 |
Retrieve | GET | 200 | 代表资源的 Atom 条目 |
Create | POST | 201 | 通过 Location 和 Content-Location 标头的新创建资源的 URI |
Update | PUT | 200 | 代表资源的 Atom 条目 |
Delete | DELETE | 200 | 无 |