《敏 捷 教 練:如何打造優秀的敏捷團隊》—6.3 與卡片共舞
913
2025-03-31
目錄
文章目錄
目錄
WSME
WSME 的使用
WSME
WSME(Web Service Made Easy)是一個 RESTful API Service Typing 庫,用于對 HTTP Request Body、Response Body、Response Status Code 進行規范化的校驗和約束。
WSME 的設計理念是:在大多數情況下,Web Services 對輸入/輸出數據類型的要求都是嚴格的。
官方文檔:https://wsme.readthedocs.io/en/latest/index.html
WSME 的使用
WSME 提供了 2 個裝飾器:
@signature:用來描述一個方法或函數的輸入/輸出數據類型。注意,大多數情況下不建議直接使用該裝飾器,而是使用為不同的 Web 框架進行封裝的 @wsexpose。
class wsme.signature([return_type, [arg0_type, [arg1_type, ..., ]]]body=None, status_code=None) # return_type – Type of the value returned by the function # argN – Type of the Nth argument # body – If the function takes a final argument that is supposed to be the request body by itself, its type. # status_code – HTTP return status code of the function. # ignore_extra_args – Allow extra/unknow arguments (default to False)
1
2
3
4
5
6
@wsexpose:包含了 @signature 的功能,也具有相同的形參列表,同時還會把方法或函數的 Route Infors 暴露給 Web 框架,類似于 Pecan 提供的 @expose 裝飾器,被裝飾的方法或函數可以被 Controller Router 找到。
# wsmeext.pecan.wsexpose(return_type, *arg_types, **options) @wsexpose(ResponseBodyType, Param01Type, Param02Type, ..., Param0NType, body=RequestBodyType, status_code={{ successfully_status_code_num }}, ignore_extra_args=True) def http_method(self, param01, param02, ..., param0N, body): ...
1
2
3
4
5
6
7
8
NOTE:對于 Error 或 Exception 的 Response Context 和 Status Code,通常直接在 raise exceptions 中定義,由 Pecan 框架捕獲之后進行響應,而不會經過 WSME 的處理,所以 WSME 也沒有這方面的邏輯。
Python
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。