Flask - nested rest api - use something other than methodview or have I made a bad design? Flask - nested rest api - use something other than methodview or have I made a bad design? flask flask

Flask - nested rest api - use something other than methodview or have I made a bad design?


I think the design is ok. MethodView should be pretty awesome for it. You can put the routes together like so:

class SymptomDiagnosisAPI(MethodView):    """    /<symptom_id>/diagnoses/        GET - list diags for symptoms        POST - {id: diagid} - create relation with diagnosis    /<symptom_id>/diagnoses/<diagnosis_id>        GET - probability symptom given diag        PUT - update probability of symptom given diag        DELETE - remove diag - symptom relation    """    def get(self, symptom_id, diagnosis_id):        if diagnosis_id is None:            return self.list_diagnoses(symptom_id)        else:            return self.symptom_diagnosis_detail(symptom_id, diagnosis_id)    def list_diagnoses(self, symptom_id):        # ...    def post(self, symptom_id):        # ...    def symptom_diagnosis_detail(self, symptom_id, diagnosis_id):        # ...        def put(self, symptom_id, diagnosis_id):        # ...        def delete(self, symptom_id, diagnosis_id):        # ...        @classmethod    def register(cls, mod):        url = "/symptoms/<int:symptom_id>/diagnoses/"        f = cls.as_view("symptom_diagnosis_api")        mod.add_url_rule(url, view_func=f, methods=["GET"],                         defaults={"diagnosis_id": None})        mod.add_url_rule(url, view_func=f, methods=["POST"])        mod.add_url_rule('%s<int:diagnosis_id>' % url, view_func=f,                         methods=['GET', 'PUT', 'DELETE'])SymptomDiagnosisAPI.register(mod)