So imagine, I have an endpoint where subscription payment to a magazine can be made.
There could be different flavors of subscription. eg, weekly, fortnight, yearly, 5 years etc.
For each subscription, the JSON request to the subscription endpoint varies in slightly different ways. For example, perhaps with the 5 years subscription, you might want to ask for the residential address, but for the weekly subscription, perhaps you do not care. Thus validation (and also business logic) differs slightly based on the subscription type.
The question is, which is the preferred way to model the endpoints:
- Have one single endpoint:
/subscription
in the JSON that is sent, you have a discriminator property. That is:{ name: "Joe", Age: 66, subscription_type: "weekly | monthly | fortnight | yearly | etc" }
So that in the implementation of/subscription
you have code that performs different validation to the JSON request and executes different business logic depending on the value of thesubscription_type
- Have separate endpoints for the different subscription types. For example:
/subscription/weekly
,subscription/monthly
etc and have the implementation of each of these endpoints to only care about the validation and business logic specific to their subscription type.
Any other option possible apart from these two I mentioned? Is there any best case practice for dealing with this kind of scenario?