Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8568421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:06:34+00:00 2026-06-11T18:06:34+00:00

Just starting off with Flask, following along at http://flask.pocoo.org/docs/views/ Say I have a basic

  • 0

Just starting off with Flask, following along at http://flask.pocoo.org/docs/views/

Say I have a basic REST api, in this case for symptoms:

/
    GET - list
    POST - create

/<symptomid>
    GET - detail
    PUT - replace
    PATCH - patch
    DELETE - delete

I can implement this pretty cleanly with Flask’s MethodView as follows:

from flask import Blueprint, request, g
from flask.views import MethodView
#...

mod = Blueprint('api', __name__, url_prefix='/api')

class SymptomAPI(MethodView):
    """ ... """

    url = "/symptoms/"

    def get(self, uid):
        if uid is None:
            return self.list()
        else:
            return self.detail(uid)

    def list(self):
        # ...

    def post(self):
        # ...

    def detail(self, uid):
        # ...

    def put(self, uid):
        # ...

    def patch(self, uid):
        # ...

    def delete(self, uid):
        # ...

    @classmethod
    def register(cls, mod):
        symfunc = cls.as_view("symptom_api")
        mod.add_url_rule(cls.url, defaults={"uid": None}, view_func=symfunc,
                         methods=["GET"])
        mod.add_url_rule(cls.url, view_func=symfunc, methods=["POST"])
        mod.add_url_rule('%s<int:uid>' % cls.url, view_func=symfunc,
                 methods=['GET', 'PUT', 'PATCH', 'DELETE'])


SymptomAPI.register(mod)

But, let’s say I would like to attach another api on these individual symptoms:

/<symptomid>/diagnoses/
    GET - list diags for symptom
    POST - {id: diagid} - create relation with diagnosis

/<symptomid>/diagnoses/<diagnosisid>
    GET - probability symptom given diag
    PUT - update probability of symptom given diag
    DELETE - remove diag - symptom relation

I would then have 4 GETs instead of two as above.

  1. Do you think this a bad api design?
  2. Would MethodView be appropriate for this design? (if the design is not bad)
  3. How would you implement these routes?

So … in writing this question, I have found a decent solution. As long as I’m here, I might as well post the question and the solution I have. Any feedback would still be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:06:35+00:00Added an answer on June 11, 2026 at 6:06 pm

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am just starting off with restkit for ios. I have a very simple json
I am just starting off Windows OEM development and have come across these two
I'm just starting with C programming (following along with 'C The Hard Way') -
I am just starting off with android and have been googling high and low
I'm just starting with PrimeFaces 3.3.1 coming off RichFaces 3 and 4. I have
I am just starting off with the world of programming C#, and have come
First off, I would like to say that I am just starting with PHP
Just starting with FactoryGirl. I have a Model named Subscription . It has a
Just starting to play around with Flask on a local server and I'm noticing
Just starting out with subversion, have set up repos for 3 current projects and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.