Gavrilo Adamovic
Gavrilo Adamovic

Reputation: 2795

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.

Upvotes: 1

Views: 503

Answers (2)

Andres
Andres

Reputation: 10717

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.

Upvotes: 2

aUserHimself
aUserHimself

Reputation: 1597

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
}

Upvotes: 1

Related Questions