title: Flask-RESTful API: multiple and complex endpoints
body: <p>In my Flask-RESTful API, imagine I have two objects, users and cities. It is a 1-to-many relationship. Now when I create my API and add resources to it, all I can seem to do is map very easy and general URLs to them. Here is the code (with useless stuff not included):</p>
  <pre><code>class UserAPI(Resource):  # The API class that handles a single user
    def __init__(self):
      # Initialize
  
    def get(self, id):
      # GET requests
  
    def put(self, id):
      # PUT requests
  
    def delete(self, id):
      # DELETE requests
  
  class UserListAPI(Resource):  # The API class that handles the whole group of Users
    def __init__(self):
  
    def get(self):
  
    def post(self):
  
  api.add_resource(UserAPI, '/api/user/&lt;int:id&gt;', endpoint='user')
  api.add_resource(UserListAPI, '/api/users/', endpoint='users')
  
  class CityAPI(Resource):
    def __init__(self):
  
    def get(self, id):
  
    def put(self, id):
  
    def delete(self, id):
  
  class CityListAPI(Resource):
    def __init__(self):
  
    def get(self):
  
    def post(self):
  
  api.add_resource(CityListAPI, '/api/cities/', endpoint='cities')
  api.add_resource(CityAPI, '/api/city/&lt;int:id&gt;', endpoint='city')
  </code></pre>
  <p>As you can see, I can do everything I want to implement a very basic functionality. I can GET, POST, PUT, and DELETE both objects. However, my goal is two-fold:</p>
  <p>(1) To be able to request with other parameters like city name instead of just
  city id. It would look something like:<br />
  <code>api.add_resource(CityAPI, '/api/city/&lt;string:name&gt;', endpoint='city') </code><br />
  except it wouldn't throw me this error:</p>
  <blockquote>
  <p>AssertionError: View function mapping is overwriting an existing
  endpoint function</p>
  </blockquote>
  <p>(2) To be able to combine the two Resources in a Request. Say I wanted to get all the
  users associated with some city. In REST URLs, it should look something like:<br />
  <code>/api/cities/&lt;int:id&gt;/users</code></p>
  <p>How do I do that with Flask? What endpoint do I map it to?</p>
  <p>Basically, I'm looking for ways to take my API from basic to useful.</p>