I'm thinking about using a new model structure for my new api.
Current state
I have GET, POST, PUT and DELETE endpoints. Just forget about DELETE because it only takes a query parameter and has no model.
Those three endpoints all use the same model:
Car Model
id: string | undefined;
manufacturer: string;
date: Date;
Problem
When requesting a single car via the GET endpoint I theoretically could get a car without a id. So when I want to pass the ID to the DELETE endpoint I always need to check that the ID is not undefined.
Possible solution
Providing different models for each HTTP method.
1. Car Model for POST request
id: string | undefined;
manufacturer: string;
date: Date;
2. Car Model for [PUT request, GET response, ...]
id: string;
manufacturer: string;
date: Date;
I also want to provide PATCH request I would also need this model
3. Car Model for PATCH request
id: string | undefined;
manufacturer: string | undefined;
date: Date | undefined;
Questions
- In total I would need three different models. But is that really worth going for and considered as a 'Good Practice'?
- If that is a 'Good Practice' how should I name the models?