简体   繁体   English

如果这个RESTful API在Flask? 为什么不?

[英]If this RESTful API in Flask? Why not?

A truly RESTful API looks like hypertext.真正的 RESTful API 看起来像超文本。 Every addressable unit of information carries an address, either explicitly (eg, link每个可寻址的信息单元都带有一个地址,或者是显式的(例如,链接

https://restfulapi.net https://restfulapi.net

The following code contains the full url. So, it is called RESTful API.以下代码包含完整的 url。因此,它被称为 RESTful API。

@app.route('/todo/api/v1.0/tasks', methods=['GET'])
def get_tasks():
    return jsonify({'tasks': tasks})

The following code doesn't contain the full url. So, it is NOT called RESTful API?以下代码不包含完整的 url。因此,它不称为 RESTful API?

@app.route("/writeOutput", methods=['POST'])

def writeOutput():
    return "Hello, World!"

My question is: What is it called when we use POST but not the full url?我的问题是:当我们使用 POST 而不是完整的 url 时,它叫什么?

Neither of the urls you've posted are full urls .您发布的两个网址都不是完整网址 They're both paths (uri) in the same application, hence they qualify for being RESTful according to the specs .它们都是同一应用程序中的路径 (uri),因此根据规范它们符合 RESTful 的条件。

However, if you have or are planning to have other versions than v1.0 , then it is not qualified as a RESTful API as they should be nouns only, ie you should write it like /todo/api/{id}/tasks this instead.但是,如果您拥有或计划拥有除v1.0以外的其他版本,则它不符合 RESTful API 的资格,因为它们应该只是名词,即您应该像/todo/api/{id}/tasks这样写反而。

I dont think the url has to do anything with an api being RESTful you read that in detail here我不认为 url 必须与 api RESTful 做任何事情你在这里详细阅读

if you call the /todo/api/v1.0/tasks with post method it will return you method not allowed as the link is only valid for get method.如果您使用 post 方法调用/todo/api/v1.0/tasks ,它将返回您method not allowed ,因为该链接仅对 get 方法有效。 if you send a request to /writeOutput with post method, def writeOutput(): will be called.如果您使用 post 方法向/writeOutput发送请求, def writeOutput():将被调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM