E
E
Eugenue Cesarevich2021-05-13 22:25:15
RESTful API
Eugenue Cesarevich, 2021-05-13 22:25:15

What is the best way to make controllers from the point of view of REST?

I have entities Student (student) and Tutor (teacher) .
There are two controllers respectively: StudentController and TutorController .

There is a task. We need to make an endpoint that will return students associated with a particular teacher. The endpoint should look like this: /tutors/{id}/students, because in this case the teacher is the main resource.

In which of the controllers would it be more logical to place this endpoint?

Pros when hosted in a StudentController:

  1. This is more logical, because the request applies specifically to students
  2. No need to duplicate StudentService in TutorController
  3. Simplifies code maintenance, since everything that concerns students is with students


2. Pros when placed in a TutorController:
  1. It seems to be more logical from the point of view of REST
  2. The code will be cleaner (because in StudentController by default the path starts with /students)


Where should the endpoint be placed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nApoBo3, 2021-05-13
@nApoBo3

The method returns students, which means that it should be placed in the students controller. Tomorrow you will need to receive students by class number, by academic performance, etc., but you will not make separate controllers for this.
You may need to split the service into two, then your teacher service will get an extra connection with the student service.

I
Ilya, 2021-05-13
@New_Horizons

Third is not given?) Another controller?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question