Good evening! I'm finally building a REST application and could use some help regarding the API design, or rather lack there of.
What I have so far works and makes sense for me, but I doubt it's a "good" design and should ask for proper help anyway. At least start now before adding error handling etc
class
Person : person entity holding info
class
Measurement : @ManyToOne to Person, a person can have many measurements, in the person's profile i can see all their measurements
class
Appointment: @OneToOne to Person, a person can have (or not) an appointment
Measurement and Appointment are the owner entities and it's a unidirectional association
Requirements:
I want to see all the persons in the database, then navigate to each profile
In the person's profile I can see their measurements, I can add or remove measurements
In the person's profile I can see if they have an appointment, if yes navigate to it
I want to see all appointments in a page, regardless of persons
Each appointment will show the person's info and nothing more
PersonController:
HTTP | Endpoint | Method |
---|
GET | /persons | findAll |
PST | /persons | createPerson |
GET | /persons/{id} | findByID |
DEL | /persons/{id} | deletePerson |
MeasurementController:
HTTP | Endpoint | Method |
---|
GET | /persons/{id}/measurements | findMeasurements |
PST | /persons/{id}/measurements | addMeasurement |
DEL | /persons/{id}/measurements/{mid} | removeMeasurement |
AppointmentController:
HTTP | Endpoint | Method |
---|
GET | /appointments | findAllAppointments |
GET | /appointments/{id} | findAppointmentByID |
DEL | /appointments/{id} | removeAppointment |
GET | /appointments/today | getTodaysAppointments |
GET | /appointments/tomorrow | getTomorrowsAppointments |
GET | /persons/{pid}/appointment | findByPersonID |
PST | /persons/{pid}/appointment | createAppointment |
With the above "design", the UI in my mind works. I've read though that all resources should be under the same path, and here I have
/persons endpoints in other controllers. Should this be redesigned or it's OK according to the requirements? Perhaps move the
/persons/{id}/appointment endpoints in the
PersonController and just leave the
/appointments/... endpoint in the
AppointmentController?