如何在一个事务中进行三个POST调用?

时间:2018-11-04 19:54:36

标签: python python-3.x rest api

我有自定义笔记创建API。设计模型的方式

首次POST通话

postURL = "http://localhost/api/v1/notes/"
addNote = {
    'title': noteTitle,
    'text' : noteText,
    'location' : noteLocation,
    'lock' : '0',
    'tags' : noteTags
}

这将提供notesID。

第二个POST呼叫:

http://localhost/api/v1/notes/images/

  • 上传多张图片

第三次POST呼叫:

http://localhost/api/v1/notes/videos/

  • 上传多个视频

这是我的代码:

def getAddNote():
    token=getToken()
    noteTitle=input("Enter Note Title: ")
    noteText=input("Enter Note Text: ")
    noteLocation=input("Enter Note Location: ")
    noteTagsInput=input("Enter Note Tags: ")

    tagList = noteTagsInput.split(",")
    print(tagList)
    tagList_=', '.join(map(lambda x: '"' + x + '"', tagList))
    noteTags="["+tagList_+"]"


    postURL = "http://localhost/api/v1/notes/"
    addNote = {
        'title': noteTitle,
        'text' : noteText,
        'location' : noteLocation,
        'lock' : '0',
        'tags' : noteTags
    }

    print(addNote)
    postrequest = requests.post(postURL , headers={'Authorization': 'Token {}'.format(token),'Content-Type': 'application/json'}, data=json.dumps(addNote))

问题:是否可以在一个事务中进行3个POST调用?

我想通过客户端应用程序提交一张照片和视频吗?

0 个答案:

没有答案