Do HATEOAS depend on context?

Viewed 16

To clarify the question, when I GET /courses for example, based on HATEOAS, besides from the course information I return data for each course such as:

{
    "courseId": 1,
    "quarter": 2,
    "year": 2021,
    "subject": {
        "subjectId": 1,
        "code": "72.07",
        "name": "Placeholder Subject",
        "link":[
            {
                "rel": "self",
                "href": "http://localhost:8080/subjects/1"
            }
        ]
    },
    "link": [
        {
            "rel": "self",
            "href": "http://localhost:8080/courses/1"
        },
        {
            "rel": "files",
            "href": "http://localhost:8080/courses/1/files"
        },
        {
            "rel": "announcements",
            "href": "http://localhost:8080/courses/1/annoucements"
        }
    ]
}

So my question is the following: what happens when i have dtos that include a course dto? Say for example, an announcement, the dto looks somewhat like this:

{
    "announcementId": 1,
    "title": "This is a placeholder title",
    "content": "This is a placeholder body text",
    "course": {
        "courseId": 1,
        "quarter": 2,
        "year": 2021,
        "subject": {
            "subjectId": 1,
            "code": "72.07",
            "name": "Placeholder Subject",
            "link": [
                {
                    "rel": "self",
                    "href": "http://localhost:8080/subjects/1"
                }
            ]
        },
        "link": [
            {
                "rel": "self",
                "href": "http://localhost:8080/courses/1"
            }
        ]
    },
    "link": [
        {
            "rel": "self",
            "href": "http://localhost:8080/announcements/1"
        }
    ]

}

Should i also put the /courses/1/files and /courses/1/announcements (this last one doesn't make that much sense but lets just suppose we have more endpoints under /courses/1/) when my context is getting the announcementes of a course or should i just put these links when i ask for a specific course/list of courses?

0 Answers
Related