Skip to content

Conversation

@nak435
Copy link

@nak435 nak435 commented Mar 19, 2023

This change makes it possible to implement a RESTful API.

for example,
PUT /RGB/YELLOW
PUT /RGB/GREEN
PUT /RGB/<any_color>

We can define these APIs in one handler.
@server.route("/RGB/*", method=HTTPMethod.PUT)

Thank you in advance for your consideration.

Comment on lines +25 to +27
if self.path[-1] == '*':
prepath = self.path[0:len(self.path)-1]
return self.method == other.method and other.path.startswith(prepath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler. You could also use self.path.rstrip("*") instead of self.path[0:-1]`

Suggested change
if self.path[-1] == '*':
prepath = self.path[0:len(self.path)-1]
return self.method == other.method and other.path.startswith(prepath)
if self.path.endswidth("*"):
return self.method == other.method and other.path.startswith(self.path[0:-1])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwriting eq method this way, it can lead to situations where A == B but B != A.

I have been thinking for a while about wildcards in URLs, already working on a more functional approach to this, that will also allow parsing those values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwriting eq method this way, it can lead to situations where A == B but B != A.

i agree with @michalpokusa's caution about this -- I wasn't sure whether it was something standard in server routing.

@nak435
Copy link
Author

nak435 commented Mar 20, 2023

I agree with @michalpokusa 's #43.
It's a great solution.
Thank you.

@nak435 nak435 closed this Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants