简体   繁体   中英

How to send put http request with multiple parameters through JSON

I have the list of students with id , firstName , lastName and email , and I have put http method that has two arguments, id and student which finds the student with given id and replace that student whit new one (second parameter).

I have to send that put http request as JSON , but I don't know how to write that request properly. This is what I tried:

{
    "id": 8,
    "firstName": "aaaa",
    "lastName": "aaaa",
    "email": "aaaa"
},
{
"id: 2"
}

So the student with id = 2 should be replaced with the student above. Basically I have trouble making this request with two parameters.

include the id of the student you want to replace on the url. Something like:

server:port/yourapp/student/2

Use the body only for the data related to the student you want to write in the db.

However, changing an id doesn't seem very restful.

You can create a custom object model that will hold a student and an additional parameter (id of another student):

{
    "student":
    {
        "id": 8,
        "firstName": "aaaa",
        "lastName": "aaaa",
        "email": "aaaa"
    },
    "studentId": 2
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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