RESTful API

RESTful API

概覽

method

方法 描述
GET(SELECT) 從服務(wù)器取出資源(一項(xiàng)或多項(xiàng))
POST(CREATE) 在服務(wù)器新建一個(gè)資源
PUT(UPDATE) 在服務(wù)器更新資源(客戶端提供改變后的完整資源)
PATCH(UPDATE) 在服務(wù)器更新資源(客戶端提供改變的屬性)
DELETE(DELETE) 從服務(wù)器刪除資源

path

URL Method Description
/users/ GET Gives a list of all users
/users/ POST Creates a new user
/users/<id> GET Shows a single user
/users/<id> PUT Updates a single user
/users/<id> DELETE Deletes a single user

status code

Code Status Method Situation
Successful 2xx
200 OK GET POST
201 Created
204 No Content POST PUT
205 Reset Content DELETE
Client Error 4xx
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
413 Request Entity Too Large POST Upload a file
415 Unsupported Media Type POST Upload a file
Server Error 5xx
500 Internal Server Error
502 Bad Gateway Use a flow

url規(guī)則

URL rules that end with a slash are branch URLs, others are leaves. If you have strict_slashes enabled (which is the default), all branch URLs that are matched without a trailing slash will trigger a redirect to the same URL with the missing slash appended.

Take these two rules:

@app.route('/projects/')
def projects():
    return 'The project page'

@app.route('/about')
def about():
    return 'The about page'

Though they look rather similar, they differ in their use of the trailing slash in the URL definition. In the first case, the canonical URL for the projects endpoint has a trailing slash. In that sense, it is similar to a folder on a file system. Accessing it without a trailing slash will cause Flask to redirect to the canonical URL with the trailing slash.

In the second case, however, the URL is defined without a trailing slash, rather like the pathname of a file on UNIX-like systems. Accessing the URL with a trailing slash will produce a 404 “Not Found” error.

This behavior allows relative URLs to continue working even if the trailing slash is ommited, consistent with how Apache and other servers work. Also, the URLs will stay unique, which helps search engines avoid indexing the same page twice.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容