1

GET /users?city="Seattle"

GET /users/{userId}

GET /users

So what im trying todo is that if they do a GET they can either find users by there city or by there ID or if they just do users they get all the users.

class Users(Resource):
def get(self,id=None):
    if id is None:
        #this return all users
    else:
        #this returns a user with specfic id 
        #the next part im trying todo is return all users from a specfic city
  • This is often done using rewrite rules in the webserver – Barmar Jul 19 '21 at 22:01
  • This really depends on what library or framework you're using to write your web server. Perhaps you can add some information about that to the question? I'd strongly recommend against rolling your own - it's generally a bad idea, especially if you're still struggling with the basics. Use a few good ones, then decide if you can do better. Flask, Quart, Django, Pyramid, there's lots of options. The aspect you're asking about is generally 'routing'. – Grismar Jul 19 '21 at 22:05
  • Im using flask for this – Francisco Perez Jul 19 '21 at 22:13
  • Check this answer: https://stackoverflow.com/a/46321103/8228558 – IoaTzimas Jul 19 '21 at 22:23
  • And this: https://stackoverflow.com/a/51385027/8228558 – IoaTzimas Jul 19 '21 at 22:25
  • inside `else` you will have to get `request.args.get('city')` and check if it has some value on `None`. – furas Jul 19 '21 at 23:51

0 Answers0