Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use workzeug for route parsing#30

Merged
sloev merged 10 commits intosloev:mastersloev/python-lambdarest:masterfrom
svdgraaf:feature/use-workzeug-for-route-parsingCopy head branch name to clipboard
Apr 6, 2018
Merged

Use workzeug for route parsing#30
sloev merged 10 commits intosloev:mastersloev/python-lambdarest:masterfrom
svdgraaf:feature/use-workzeug-for-route-parsingCopy head branch name to clipboard

Conversation

@svdgraaf
Copy link
Contributor

@svdgraaf svdgraaf commented Apr 5, 2018

TL/DR: This PR makes paths like /foo/bar/<int:id>/ work.

I needed path parameter support for my api, I noticed that Workzeug (from Flask) solved that issue already, and here we are.

  • I added a dependency on workzeug
  • I added the mapper for mapping the function calls
  • I added a short description in the readme

Copy link
Owner

@sloev sloev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, can you fix the following issues and can you add a test for the path_params

except KeyError:
logging.warning(logging_message.format(
status_code=405, message="Not supported"))
error_tuple = ("Not supported", 405)
Copy link
Owner

Choose a reason for hiding this comment

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

What raises the KeyError and tells us that the HTTP method is unsupported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The KeyError was from before, removed it, not needed anymore.

logging_message = "[%s][{status_code}]: {message}" % method_name
try:
func = http_methods.get(path, http_methods.get("*", {}))[method_name]
mapping = url_maps.bind('example.com', '')
Copy link
Owner

Choose a reason for hiding this comment

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

what does example.com have to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured we needed an server_name to bind it, but it's actually not needed at all, removed it.


# register http handler function
http_methods.setdefault(path.lower(), {})[method_name.lower()] = inner
# url_maps.setdefault(path.lower(), {})[method_name.lower()] = inner
Copy link
Owner

Choose a reason for hiding this comment

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

remove

http_methods.setdefault(path.lower(), {})[method_name.lower()] = inner
# url_maps.setdefault(path.lower(), {})[method_name.lower()] = inner
rule = Rule(path, endpoint=inner, methods=[method_name.lower()])
print(rule)
Copy link
Owner

Choose a reason for hiding this comment

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

no prints

@sloev
Copy link
Owner

sloev commented Apr 5, 2018

When tests are green we can merge

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 5, 2018

@sloev ok, working on it

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 5, 2018

@sloev I fixed all the tests, but the py33 one is stuck, it seems to break on installing a dependency, but I'm not sure.

@sloev
Copy link
Owner

sloev commented Apr 5, 2018

I can fix the last one. Its because pylint no longer supports py3.3

@sloev sloev merged commit 9f8c9d5 into sloev:master Apr 6, 2018
@sloev
Copy link
Owner

sloev commented Apr 6, 2018

good job @svdgraaf :-)

sloev pushed a commit that referenced this pull request Apr 6, 2018
* pep8 cleanup

* Added werkzeug dependency

* Use the werkzeug Map() object to do the mapping for us

* Added description for using the path parameters

* bind to an empty server name

* Make readme have unique urls, all tests are run in the same context

* Add exception for catch-all rule so * can be used as path

* fixed absolute url redirect

* fix pylint for py3.3

* bump version, write history
@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 6, 2018

Thanks @sloev! Combining this with the Serverless framework makes it a lot easier to write a bit bigger api 😄

Stuff like this is awesome:

@lambda_handler.handle("post", path="/foo/<int(fixed_digits=12):account_id>/")
def invoke_foo(request, account_id):

@sloev
Copy link
Owner

sloev commented Apr 6, 2018

hahaha Truly Awesome!!! Yeah i really like the lambda_handler "singleton" and that it's just a function. Python FTW.

Please come back if you find bugs or have new features, nice collaborating wit you!

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.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.