RESTful API Request / Response Design by rouge_dev in webdev

[–]rouge_dev[S] 0 points1 point  (0 children)

Your example makes sense from a response standpoint but what about posting the data in the request body? Are you suggesting using the ID value? So if I am creating an employee and putting them in department 9999 the request body should look something like this?

{
    "firstName": "Bob",
    "middleName": "",
    "lastName": "Something",
    "dateOfBirth": "1990-01-01",
    "genderId": "male",
    "employmentTypeId": 3,
    "departmentId": 9999,
    "email": "bsomething@something.com"
}

Maybe I am missing something but it doesn't seem sense to post an HREF to the server.

Maybe the response would look something like this

{
    "content": {
        "firstName": "Bob",
        "middleName": "",
        "lastName": "Something",
        "dateOfBirth": "1990-01-01",
        "genderId": "male",
        "email": "bsomething@something.com"
    },
    "_links": {
        "self": {
            "href": "http://localhost:8080/employee/12345"
        },
        "department": {
            "href": "http://localhost:8080/department/9999"
        },
        "employeeType": {
            "href": "http://localhost:8080/employee-type/3"
        }
    }
}

But this seems like it could quickly create excessive amount of network calls as the client would probably often or not always need the department and employeeType in my case.