Skip to content

Instantly share code, notes, and snippets.

@timothycrosley
Created March 18, 2016 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothycrosley/a26a02569396f658bc9f to your computer and use it in GitHub Desktop.
Save timothycrosley/a26a02569396f658bc9f to your computer and use it in GitHub Desktop.
Class based routing
import hug
# As a pattern for reuse
@hug.object.urls('/endpoint', requires=())
class MyClass(object):
@hug.object.get()
def my_method(self):
return 'hi there!'
@hug.object.post()
def my_method_two(self):
return 'bye'
# Or, just a way to group related functionality
@hug.object.http_methods()
class Contact(object):
def get(self):
return 'retrieving contact'
def post(self):
return 'creating contact'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment